HDU-1422 -重温世界杯 - 环上的最长连续子序列

来源:互联网 发布:东莞软件检测机构 编辑:程序博客网 时间:2024/05/19 00:39

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1422

理解题意,没什么好说的

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAX=100010;int life[MAX],cost[MAX],res[2*MAX];bool cmp(int a,int b){    return a>b;}int  main(){    int n;    while(~scanf("%d",&n))    {        memset(life,0,sizeof(life));        memset(cost,0,sizeof(cost));        memset(res,0,sizeof(res));        int temp,num,count,i,j;         for(i=0;i<n;i++)         {             scanf("%d%d",&life[i],&cost[i]);             res[n+i]=res[i]=life[i]-cost[i];  //注意,关键         }         temp=0;         num=0;          count=0;        for(i=0;i<2*n;i++)        {           if(temp<count)      temp=count ;  //最多参观的城市数目                       if(res[i]>=0||(num+res[i])>=0)            {                num+=res[i];                count++;            }           else               {               count=0;               num=0;           }                }    //        printf("%d\n",temp); 尼码         printf("%d\n",temp>n?n:temp);  //count计数是在2n个城市中,temp有可能超出n    }    return 0;}


 

0 0