Subsequences Summing to Sevens
Subsequences Summing to Sevens
题目描述
Please help FJ determine the size of the largest group he can photograph.
输入
输出
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++.
样例输入
7
3
5
1
6
2
14
10
样例输出
5
提示
In this example, 5+1+6+2+14 = 28.
分析:(i+j)%k=i%k,则j是k的倍数;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <bitset>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e6+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m;
ll a[maxn],pre[],last[],now;
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,n){
scanf("%lld",&a[i]);
now=(now+a[i])%;
if(pre[now])last[now]=i;
else pre[now]=i;
}
ll ma=;
rep(i,,)
{
if(pre[i]&&last[i])ma=max(ma,last[i]-pre[i]);
}
printf("%lld\n",ma);
//system ("pause");
return ;
}
Subsequences Summing to Sevens的更多相关文章
- [USACO16JAN]子共七Subsequences Summing to Sevens
[USACO16JAN]子共七Subsequences Summing to Sevensa[i]表示前缀和如果a[i]%7==t&&a[j]%7==t那么a[j]-a[i-1]一定是 ...
- 洛谷 P3131 [USACO16JAN]子共七Subsequences Summing to Sevens
P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题目描述 Farmer John's NN cows are standing in a row ...
- bzoj4511:[Usaco2016 Jan]Subsequences Summing to Sevens
题目大意:给个序列,求最长的连续子序列使其为7的倍数 又是一道令人欢喜的不用怎么用脑的水题.. 边读入,边计算前缀和 分别保存前缀和%7结果为1,2,3,4,5,6的第一次的位置 然后减一减就知道长度 ...
- bzoj4511: [Usaco2016 Jan]Subsequences Summing to Sevens
前缀和. 设f[i]为前缀和%7=i的第一个点.那么答案就是max(i-f[s[i]%7])了. #include<cstdio> #include<algorithm> #i ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 刷题总结(持续更新)
本篇博客按照题号排序(带*为推荐题目) 1008 [HNOI2008]越狱 很经典的题了..龟速乘,龟速幂裸题,, 1010 [HNOI2008]玩具装箱toy* 斜率优化 基本算是裸题. 1012 ...
- 【洛谷P3131】 【USACO16JAN】子共七
P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题目描述 Farmer John's cows are standing in a row, a ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- [LeetCode] Distinct Subsequences 不同的子序列
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
随机推荐
- vs2013执行Add-Migration出现的问题
1. 无法将"Add-Migration"项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次 网上解决方法为:h ...
- ip forward
centos vi /proc/sys/net/ipv4/ip_forward ubuntu vi /etc/sysctl.conf sysctl -p
- freemarker中的list 前端模板
freemarker list (长度,遍历,下标,嵌套,排序)1. freemarker获取list的size : JavaArrayList<String> list = new Ar ...
- php.ini与php-fpm.conf配置文件的区别
php-fpm.conf是PHP-FPM特有的配置文件 php.ini是所以php模式中必须的配置文件 两者的区别是,php-fpm.conf是PHP-FPM进程管理器的配置文件,php.ini是PH ...
- Thinkphp中使用Redis
先确保安装了redis扩展 添加Redis配置 'REDIS_HOST'=>'192.168.0.2', 'REDIS_PORT'=>6379, 其他配置根据自己ThinkPHP版本,找到 ...
- QML Flipable、Flickable和状态与动画 上篇
本文介绍的是QML Flipable.Flickable和状态与动画,我们以前接触过QML组件,和一些QML相关的内容,那么本文介绍的内容就很明了了.先来看内容. AD:51CTO 网+ 第十二期沙龙 ...
- UIImageView 在切图规范的情况下不用设置frame
UIImageView本身是没有frame的,所以UIImageView不用设置frame,UIImageView的fram由它内部的图片决定,所以当要更改UIImageView的大小显示的时候,更改 ...
- C、C++的Makefile的编写以及动、静态库的制作调用(包括MAC地址的获取及MD5加密)
一.C代码 静态库 四个.h.c文件 add.h #ifndef ADD_H #define ADD_H int add(int a,int b); #endif add.c #include < ...
- 1.1 整理的Linux 基础
本文总参照:http://blog.csdn.net/xiaoguaihai/article/details/8705992/ 2.用户管理操作命令 (1)Su - XX 切换用户 3.文件管理操作命 ...
- opencv-----基本数据类型
OpenCV提供了多种基本数据类型.可以在"…/OpenCV/cxcore/include"目录下的cxtypes.h文件中查看其详细定义. CvPoint是一个包含integer ...