bzoj4512: [Usaco2016 Jan] Build Gates

题目大意:给个序列,求最长的连续子序列使其为7的倍数

又是一道令人欢喜的不用怎么用脑的水题。。

边读入,边计算前缀和

分别保存前缀和%7结果为1,2,3,4,5,6的第一次的位置

然后减一减就知道长度啦。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int n,t,last[8],ans;
 6 long long sum[50010];
 7 int main(){
 8     scanf("%d", &n);
 9     ans=0;
10     for (int i=1; i<=n; i++){
11         scanf("%lld", &sum[i]);
12         sum[i]+=sum[i-1];
13         t=sum[i]%7;
14         if (!last[t]) last[t]=i;
15         ans=max(ans,i-last[t]);
16     }
17     printf("%d\n", ans);
18     return 0;
19 } 
时间: 2024-10-12 21:50:57

bzoj4512: [Usaco2016 Jan] Build Gates的相关文章

bzoj 4506: [Usaco2016 Jan]Fort Moo

4506: [Usaco2016 Jan]Fort Moo Description Bessie is building a fort with her friend Elsie. Like any good fort, this one needs to start with a sturdy frame. Bessie wants to build a frame in the shape of a one-meter-wide rectangular outline, atop which

bzoj4509【Usaco2016 Jan】Angry Cows

4509: [Usaco2016 Jan]Angry Cows Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 83  Solved: 38 [Submit][Status][Discuss] Description Bessie the cow has designed what she thinks will be the next big hit video game: "Angry Cows". The premise, whi

bzoj4510: [Usaco2016 Jan]Radio Contact

bzoj4510: [Usaco2016 Jan]Radio Contact Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved: 17[Submit][Status][Discuss] Description Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan ou

bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens

前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 50000 + 10; int a[maxn],s[maxn]; int f[10],n,ans; int main() { for(int i=1;i<7;i++) f[i]=-1;

bzoj4525: [Usaco2016 Jan]Angry Cows

二分. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 50000 + 10; int n,k,l,r,mid,ans,d; int a[maxn]; bool check(int dist) { dist=2*dist; int d=0,sum=1; for(int i=2;i<=n;i++) { if(a[i]-a[i-1]

[BZOJ4506] [Usaco2016 Jan]Fort Moo(DP?)

传送门 总之可以先预处理出来每个位置最多往上延伸多少 枚举两行,看看夹在这两行中间的列最大能构成多大的矩形 可以看出,必须得在一个两行都没有X的区间才有可能构成最大的答案 那么可以把这些区间处理出来,在看看这些区间中的点最左边和最右边的能从下面那一行向上延伸到上面那一行的点,更新ans即可 #include <cstdio> #define N 201 #define max(x, y) ((x) > (y) ? (x) : (y)) int n, m, ans, p; int h[N]

BZOJ2021: [Usaco2010 Jan]Cheese Towers

2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 184  Solved: 107[Submit][Status] Description Farmer John wants to save some blocks of his cows' delicious Wisconsin cheese varieties in his cellar for the coming winter.

BZOJ 3887[Usaco2015 Jan]Grass Cownoisseur

题面: 3887: [Usaco2015 Jan]Grass Cownoisseur Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 237  Solved: 130[Submit][Status][Discuss] Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow pat

[BZOJ] 1636: [Usaco2007 Jan]Balanced Lineup

1636: [Usaco2007 Jan]Balanced Lineup Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 909  Solved: 644[Submit][Status][Discuss] Description For the daily milking, Farmer John's N cows (1 <= N <= 50,000) always line up in the same order. One day Farmer