[USACO16JAN]子共七Subsequences Summing to Sevens
2024-08-20 15:01:34
[USACO16JAN]子共七Subsequences Summing to Sevens
a[i]表示前缀和
如果a[i]%7==t&&a[j]%7==t
那么a[j]-a[i-1]一定是7的整数倍,
这样就o(n)扫一遍,不断更新答案就可以了。
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.12
using namespace std;
long long n;
long long a[];
long long p[];
long long x,l,ans;
void in(long long &x)
{
char c=g();x=;
while(c<''||c>'')c=g();
while(c<=''&&c>='')x=x*+c-'',c=g();
}
void o(long long x)
{
if(x>)o(x/);
p(x%+'');
}
int main()
{
in(n);
For(i,,n)
{
in(x);
a[i]=x+a[i-];
}
/* for(register long long len=n;len>=1;len--)
{
For(i,1,n-len+1)
if((a[i+len-1]-a[i-1])%7==0)
{
o(len);
exit(0);
}
}*/
For(i,,)
p[i]=inf;
For(i,,n)
{
p[a[i]%]=min(p[a[i]%],i);
ans=max(ans,i-p[a[i]%]);
}
o(ans);
return ;
}
最新文章
- 【UOJ #13】【UER #1】跳蚤OS
- editplus如何配置php编译环境?
- ProgressDialog的使用
- Python语言精要---下
- VC高手们的博客
- php开发学习目录
- 删除WIN7系统的共享文件
- MFC永久窗口对象与临时窗口对象
- Python ---------copy
- 【Alpha】阶段总结报告
- Unsupported&#160;major.minor&#160;version&#160;52.0
- 设计模式のObserver Pattern(观察者模式)----行为模式
- thinkphp 在本地正常,在云端ubuntu下报控制器不存在
- 九、使用多线程——NSThread,GCD和NSOperation
- WinForm版图像编辑小程序(实现图像拖动、缩放、旋转、抠图)
- [ci]jenkins-slave的添加(vm模式,通过ssh和jnlp)
- HBase的Shell命令和JavaAPI
- getHibernateTemplate()的用法 (转)
- C#使用Gzip解压缩完整读取网页内容
- Objective-C系列总结之基础知识