hdu 1422 重温世界杯

本文提供了一种解决 HDU 1422 编程问题的有效算法。该算法通过预处理输入数据并使用动态规划来确定最优解,确保了计算效率和准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://acm.hdu.edu.cn/showproblem.php?pid=1422

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 200000
 5 #define ll __int64
 6 using namespace std;
 7 
 8 ll w[maxn],l[maxn],c[maxn];
 9 int n;
10 
11 int main()
12 {
13     while(scanf("%d",&n)!=EOF)
14     {
15         for(int i=0; i<n; i++)
16         {
17             scanf("%I64d%I64d",&w[i],&l[i]);
18             c[i]=w[i]-l[i];
19             c[i+n]=c[i];
20         }
21         ll ans=0;
22         int cnt=0;
23         int max1=0;
24         for(int i=0; i<2*n; i++)
25         {
26             ans+=c[i];
27             cnt++;
28             if(ans<0)
29             {
30                 ans=0;
31                 cnt=0;
32             }
33             max1=max(max1,cnt);
34             if(cnt>=n) break;
35         }
36         printf("%d\n",max1>n?n:max1);
37     }
38     return 0;
39 }
View Code

转载于:https://www.cnblogs.com/fanminghui/p/3867260.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值