HDU 1422-Relive the World Cup (Problem solving report)

Source: Internet
Author: User

Relive the World CupTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5407 Accepted Submission (s): 1859


Problem description The end of the World Cup, Italians even brought back the French debt owed to them 6 years ago, took up the cup of Hercules, the achievement of 4 star Italy.
The World Cup is over, but the World Cup has left us with a lot to remember. For example, we heard the yellow name of the mouth of the 3-minute passionate commentary, we learned that the original can be presented to the same person 3 yellow cards, we also saw Zidane's head can not only ball can also top people ...
There are so many wonderful, Xhd decided to revisit the German World Cup, of course, just go to the host World Cup tournament to take a look at the city. But it takes a lot of money, and fortunately Xhd's love for the World Cup has moved the World Cup organizing Committee, They will provide a round-trip ticket to the city of Xhd in China, Hangzhou and Germany, and persuade the cities to provide him with a living allowance when Xhd arrives in the city, so that when he visits there, the rest of the money will be left to XHD, But when the cost of living is not enough, they will force the end of XHD's trip to Germany, in addition to this, they have a condition, XHD only according to their route to visit. For example, there are 3 cities a,b,c, they given a-b-c-a route, then XHD only 3 kinds of tour order ABC,BCA, Cab. Because the cost of living and spending there are different in each city, it makes XHD very headache, fortunately we know the cost of living and expenses in advance. How many cities can XHD visit?
Input data in each group is divided into two lines, the first line is a positive integer n (1<=n<=100000), indicating that there are N cities. The next line is the output of the N cities according to the given route order, the cost of living and spending, W1,l1,w2,l2,......, Wn,ln, of which WI , Li represents the cost of living and spending for the first city, and they are all positive integers.
Output corresponds to the maximum number of cities that can be visited for each set of data.
Sample Input
33 2 3 4 2 233 2 3 4 2 3

Sample Output
32

The following:

Because the city is a ring, so it is twice times the length of the array records to each city, the violent run once can pass.

Reference code:

#include <stdio.h> #define M 200005int a[m];int main () {int n;while (~scanf ("%d", &n) {int x,y,max,ans,num;max= 0;for (int i=1;i<=n;i++) {scanf ("%d%d", &x,&y); a[i]=x-y;a[n+i]=x-y;} ans=0;        num=0;for (int j=1;j<=2*n;j++) {    ans+=a[j];    if (ans>=0)        num++;    else    {if (Num>max)            max=num;                num=0;                ans=0;    } if (num==n)            {               max=n;               break;            }} printf ("%d\n", Max);} return 0;}



Copyright NOTICE: This article for Bo Master original article, casually reproduced.

HDU 1422-Relive the World Cup (Problem solving report)

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.