Find the Water king

Source: Internet
Author: User
Tags net time

I.. title and title requirements

Topic:

A three-person line designed a forum for irrigation. Information college students like to exchange irrigation above, legend in the forum there is a "water king", he not only likes to post, but also reply to other ID issued by each post. The "Water King" has been rumored to have posted more than half the number of posts. If you have a list of posts (including replies) for the current forum, and the ID of the author of the Post is in it, can you quickly find the legendary water king?

Second, design ideas:

See this topic, just start their own thinking is the sort, what binary sort bubble sort, but are too cumbersome, the complexity is also high, then according to the teacher in class to the hint "subtract", and then have the following some new ideas.

Because the water paste King post more than half, so, the list of posts from the first ID, 22 adjacent to the comparison, and then the ID is different to eliminate, the last remaining must be the water King ID.

Because the post must have a total serial number of the table statistics, so first save this table as an array

1, the list of posts, abstract as a one-dimensional array arr[num], input length is the total number of IDs, each array element is an ID.

2, and then set a loop, in order to 22 comparison, if the author ID is the same, and if the author ID is different to eliminate.

3, the last remaining ID is the water King ID

Third, the source program:

#include <iostream>using namespacestd;#defineNUM 100intFindintArr[],intN//find out the function of the water king {     intShuiwang; intFindshuiwang =0; intCount=0;//Mark      for(intI=0; i<n;i++)     {          if(Count = =0)//Initially, assign the first element of the array to the Shuiwang{Shuiwang=Arr[i]; Count=1; }          Else         {              if(Shuiwang = = Arr[i])//they don't eliminate each other when they are equal.Count + +; Else //eliminate each other when they are not equalCount--; }     }         returnShuiwang; }intMain () {intLength=0;//define the length of an array firstcout<<"Please enter the value of n"<<Endl; CIN>>length; intArr[num]; cout<<"Please enter the ID (not 0):"<<Endl;  for(intI=0; I<= (length-1); i++) {cin>>Arr[i]; }       intId=find (Arr,length); cout<<"the ID of the Navy is"<<ID<<Endl; return 0;}

Four, the operation

v. Project plan log

Dates && Tasks

Lectures Writing Programs Read related books Find information online Total Day
Monday 100 30 30 160
Tuesday 30 30 60
Wednesday 30 30 10 70
Thursday 100 20 30 150
Friday 120 30 30 180
Saturday
Sunday
Weekly totals 200 170 150 100

620

Time Recording Log

5/16

Date Start time End time Interrupt Time NET time Activities Note
5/16 14:00 15:50 10 100 Lectures Software Engineering Classes
21:04 21:34 0 30 Read books "Dream Break Code"
22:10 22:40 0 30 Find information online
5/17 18:00 18:30 0 30 Read books "Dream Break Code"
22:15 22:45 0 30 Find information online
5/18 19:25 20:00 5 30 Writing Programs Find the Water king
22:00 22:30 0 30 Read books "Dream Break Code"
22:40 22:50 0 10 Find information
5/19 14:00 15:50 10 100 Class Software Engineering on-machine
18:26 18:50 4 20 Writing Programs Find the Water king
22:00 22:30 0 30 Read books "Dream Break Code"
5/20 14:00 16:20 20 120 Writing Programs Pair development-the sum of sub-arrays
11:23 12:00 7 30 Find information online
21:00 21:30 0 30 Read books The law of Construction

Vi. Personal Summary

For this topic, the beginning of the train of thought, I think is also the majority of students have some ideas, is the sort, the big deal on a one to find and then accumulate the total number of their ID number, but this method is not easy in terms of complexity and many aspects, and then in the teacher's prompt "subtraction", And then there's a new thought. Later the teacher mentioned the traversal and then sort, the middle is definitely the water King ID, but the time complexity for n*n, in order to reduce the complexity of time, the teacher suggested with 22 elimination of ideas, then we thought how to solve. Thus, our thinking is not very open, confined to those who have learned the simple common knowledge, so I still have a lot of room for progress.

Find the Water king

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.