HDU 4883 tiankeng's Restaurant

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4883

Solution Report: There are n waves of guests in a restaurant each day. The arrival time of the I wave k guest is S, and the departure time is E. How many people can find the most popular restaurants?

At first, I wrote it using a line segment tree, but re. Later I saw a method that was very clever: all the time in a day was converted into minutes, ranging from 0 to 1440, all are initialized to 0, and if there are K

When the guests arrive, they will be in the s position + K of the array, and then-K at the departure time. Finally, they will scan the array and judge the maximum value during the scanning process.

 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int maxn = 1500; 7 int que[maxn],T,n; 8  9 int main()10 {11     scanf("%d",&T);12     while(T--)13     {14         scanf("%d",&n);15         memset(que,0,sizeof(que));16         int d,s1,s2,e1,e2;17         while(n--)18         {19             scanf("%d %d:%d %d:%d",&d,&s1,&s2,&e1,&e2);20             s1 = 60 * s1 + s2;21             e1 = 60 * e1 + e2;22             que[s1] += d;23             que[e1] -= d;24         }25         int tot = 0,ans = 0;26         for(int i = 0;i <= 1440;++i)27         {28             tot += que[i];29             ans = max(ans,tot);30         }31         printf("%d\n",ans);32     }33     return 0;34 }
View code

 

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.