UVa 507 - Jill Rides Again
2016-04-05 19:00
447 查看
动态规划
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 #define MAXN 20002 7 8 int routes,stopNum; 9 int stops[MAXN]; 10 int maxSum,st,en,newSt; 11 12 int main() 13 { 14 #ifndef ONLINE_JUDGE 15 freopen("D:\\acm.txt","r",stdin); 16 #endif // ONLINE_JUDGE 17 18 cin>>routes; 19 for(int i = 1;i <= routes;i++){ 20 memset(stops,0,sizeof(stops)); 21 maxSum = 0;newSt = st = en = 1; 22 cin >> stopNum; 23 for(int j = 1;j < stopNum;j++) cin>>stops[j]; 24 //////////////////////////// 25 int m,sum = 0; 26 for(m = 1;m < stopNum;m++){ 27 if(sum < 0){ 28 sum = 0; 29 st = m;//更新起点 30 } 31 sum += stops[m]; 32 if(sum > maxSum || (sum == maxSum && m - st > en - newSt))//和相等时取长度大的;长度相同时,取起点最小的。 33 { 34 maxSum = sum; 35 newSt = st; 36 en = m; 37 } 38 } 39 if(maxSum > 0) 40 cout<<"The nicest part of route "<<i<<" is between stops "<<newSt<<" and "<<en + 1<<endl; 41 else 42 cout<<"Route "<< i <<" has no nice parts"<<endl; 43 } 44 return 0; 45 }
相关文章推荐
- Xcode localization failed to read a strings file问题原因
- CMS GC时出现promotion failed跟concurrent mode failure
- 俄罗斯Mail.Ru云端部署视频的技术架构解析
- AIDL[1] 什么是AIDL?
- http://blog.csdn.net/emoven/article/details/12999265
- SDL2-2.0.4出现Could not initialize SDL : No available video device
- [LeetCode-70] Climbing Stairs
- How to use AIDL
- RAID 0 1 5 6 0+1
- POJ 3580 OpenJ_Bailian 4090 SuperMemo (伸展树模版)
- Codeforces 616E Sum of Remainders 【数学分块】
- 【转】Adnroid4.0 签名混淆打包(conversion to dalvik format failed with error 1)
- mybaits批量插入
- lightoj 1223 - Testing Mailboxes 区间DP
- Gradle sync failed: Out of memory: PermGen space
- AFNetworking的报错Error Domain=NSURLErrorDomain Code=-1012 解决问题
- 56 RAII实现智能指针
- gdb在运行maintenance info program-spaces命令时coredump
- 移动诊疗和人工智能序言
- intellij创建安卓项目时Crunching cruncher ***.png failed的解决