抽屉原理
来源:互联网 发布:淘宝账号注册自动 编辑:程序博客网 时间:2024/06/10 04:22
F - 鸽巢原理入门2
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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).
Input
The first line of the input contains the single number N. Each of next N lines contains one number from the given set.
Output
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.
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.
Sample Input
512341
Sample Output
223
#include<stdio.h>#include<string.h>__int64 s[10010];int a[10010],c[10010];int main(){int n;while(~scanf("%d",&n)){memset(c,-1,sizeof(c));s[0] = 0;c[0] = 0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);s[i] = s[i-1]+a[i];}for(int i=1;i<=n;i++){if(c[s[i]%n]!=-1){printf("%d\n",i-c[s[i]%n]);for(int j=c[s[i]%n]+1;j<=i;j++)printf("%d\n",a[j]);break;}c[s[i]%n] = i;}}}
0 0
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理...
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理
- 抽屉原理?
- C++ primer学习笔记 第12章
- <<node.js探秘>>(01).入门
- 提高沟通效果的十个技巧
- Julia: reduce 、mapreduce、filter
- 稀疏表示step by step
- 抽屉原理
- asp.net EF的简单使用
- 企鹅我认为其认为恶趣味
- poj 1811 Prime Test(数论:大素数判定-分解)
- redis如何检测lua脚本的合理性。
- hdu 寒冰王座
- 一个密码改变了我的人生
- Dxva
- 网站出问题怎么办