BZOJ 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
来源:互联网 发布:淘宝站外推广怎么做 编辑:程序博客网 时间:2024/06/10 17:43
4511: [Usaco2016 Jan]Subsequences Summing to Sevens
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 197 Solved: 149
[Submit][Status][Discuss]
Description
Farmer John's N cows are standing in a row, as they have a tendency to do from time to time. Each cow is labeled with a distinct integer ID number so FJ can tell them apart. FJ would like to take a photo of a contiguous group of cows but, due to a traumatic childhood incident involving the numbers 1…6, he only wants to take a picture of a group of cows if their IDs add up to a multiple of 7.
Please help FJ determine the size of the largest group he can photograph.
The first line of input contains N(1≤N≤50,000). The next N lines each contain the N integer IDs of the cows (all are in the range 0…1,000,000
).
给定长度为N的数列A,求A最长的连续子序列,满足子序列中元素的和是7的倍数。输出最大的长度。如果不存在满
足条件的子序列,输出0。1 ≤ N ≤ 50000, 0 ≤ A_i ≤ 10 ^ 6
Input
Please output the number of cows in the largest consecutive group whose IDs sum to a multiple of 7. If no such group exists, output 0.
Output
You may want to note that the sum of the IDs of a large group of cows might be too large to fit into a standard 32-bit integer. If you are summing up large groups of IDs, you may therefore want to use a larger integer data type, like a 64-bit "long long" in C/C++.
Sample Input
7
3
5
1
6
2
14
10
3
5
1
6
2
14
10
Sample Output
5
In this example, 5+1+6+2+14 = 28.
In this example, 5+1+6+2+14 = 28.
刷水有益健康
维护前缀和就行了
BJ处理了一下连续0的情况
搞的rank超低
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=50010;int con[N],sum[N],last[7];int main(){int n=read();register int i,x,ans=0;for(i=1;i<7;++i)last[i]=n;for(i=1;i<=n;++i){con[i]=con[i-1];sum[i]=sum[i-1];x=read();if(x){x%=7;con[i]++;(sum[i]+=x)%=7;}last[sum[i]]=min(last[sum[i]],i);if(con[i]-con[last[sum[i]]]>0)ans=max(ans,i-last[sum[i]]);}print(ans);puts("");return 0;}
阅读全文
0 0
- 【BZOJ】4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- BZOJ 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- bzoj 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- [bzoj4511][Usaco2016 Jan]Subsequences Summing to Sevens
- BZOJ 4511 Subsequences Summing to Sevens (前缀和)
- Subsequences Summing to Sevens
- Subsequences Summing to Sevens(前缀和)
- YMS Round #1 Div. 2 D Subsequences Summing to Sevens
- BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
- BZOJ 4510: [Usaco2016 Jan]Radio Contact dp
- bzoj4509【Usaco2016 Jan】Angry Cows
- bzoj4512: [Usaco2016 Jan] Build Gates
- BZOJ4525——[Usaco2016 Jan]Angry Cows
- 【BZOJ4510】[Usaco2016 Jan]Radio Contact【DP】
- USACO2016 Jan Bronze 2:Angry Cows
- USACO2016 Jan Bronze 3:Mowing the Field
- USACO2016 Jan Bronze 1:Promotion Counting
- USACO2016 Jan Bronze 4:Promotion Counting
- 初级bash-shell脚本编写和练习
- CSU-ACM2017暑期训练16-树状数组 A
- 与BS的第一次邂逅
- 远程来电流程分析---之一
- 面向对象设计模式实践之抽象工厂模式
- BZOJ 4511: [Usaco2016 Jan]Subsequences Summing to Sevens
- Maven详解
- HDU6053TrickGCD(莫比乌斯函数)
- 【二分答案&&最短路】URAL
- 阿里在线编程测验——兔子繁衍问题
- linux top显示的各个符号参数意义详解
- Java中的异常处理机制《转载》
- 登录脚本重构Element
- C