Find a multiple POJ
来源:互联网 发布:linux 脚本 批量执行 编辑:程序博客网 时间:2024/05/24 01:49
Find a multiple POJ - 2356
The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000. This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task is to choose a few of given numbers ( 1 <= few <= N ) so that the sum of chosen numbers is multiple for N (i.e. N * k = (sum of chosen numbers) for some natural number k).
The first line of the input contains the single number N. Each of next N lines contains one number from the given set.
In case your program decides that the target set of numbers can not be found it should print to the output the single number 0. Otherwise it should print the number of the chosen numbers in the first line followed by the chosen numbers themselves (on a separate line each) in arbitrary order.
If there are more than one set of numbers with required properties you should print to the output only one (preferably your favorite) of them.
Input
5
1
2
3
4
1
Output
2
2
3
#pragma comment(linker, "/STACK:1024000000,1024000000")//#include <bits/stdc++.h>#include<string>#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<queue>#include<stack>#include<vector>#include<set>#include<algorithm>#define maxn 10600#define INF 0x3f3f3f3f#define eps 1e-8#define MOD 1000000007#define ll long longusing namespace std;int A[maxn],vis[maxn],sum[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(vis,-1,sizeof vis); sum[0]=0; int a,b; vis[0]=0; for(int i=1;i<=n;i++) scanf("%d",&A[i]); for(int i=1;i<=n;i++) { sum[i]=(sum[i-1]+A[i])%n; if(vis[sum[i]]==-1) vis[sum[i]]=i; else { a=vis[sum[i]]; b=i; break; } } printf("%d\n",b-a); for(int j=a+1;j<=b;j++) printf("%d\n",A[j]); } return 0;}
- Find a multiple POJ
- Find a multiple (POJ
- Find a multiple POJ
- poj 2365 Find a multiple
- POJ 2356 Find a multiple
- POJ,2356,Find a multiple
- poj 2356 Find a multiple
- poj 2356 Find a multiple
- poj - 2356 Find a multiple
- Poj 2356Find a multiple
- poj 23565-Find a multiple
- POJ 2356 Find a multiple
- poj 2356 Find a multiple dfs 爆搜!!!!
- POJ 2356 Find a multiple [抽屉原理]
- 北大POJ 2356 find a multiple
- POJ-2356 Find a multiple ----抽屉原理
- [置顶]poj-2356-Find a multiple
- [POJ 2356]Find a multiple(抽屉原理)
- 杭电ACM1000
- Python报错信息与原因分析
- /usr/local/lib/libpython2.7.a: could not read symbols: Bad value. collect2: ld retur ned 1 exit
- jquery+css实现下拉列表
- “GetModuleFileNameW”: 不能将参数 2 从“char [260]”转换为“LPWSTR”
- Find a multiple POJ
- hadoop 压缩解压
- Humble Numbers(hdoj1058)
- [NOIP模拟赛]分钱
- ESP8266程序烧写
- 标签总结
- 简单文件上传到服务器
- 假期总结开学计划
- The Google File System : part7 EXPERIENCES