博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2356 Find a multiple
阅读量:4599 次
发布时间:2019-06-09

本文共 2010 字,大约阅读时间需要 6 分钟。

Find a multiple

Time Limit: 1000ms
Memory Limit: 65536KB
This problem will be judged on 
PKU. Original ID: 
64-bit integer IO format: %lld      Java class name: Main
 
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.
 

Sample Input

512341

Sample Output

223

Source

 
解题:抽屉原理
1 #include 
2 #include
3 #include
4 using namespace std; 5 const int maxn = 10010; 6 int a[maxn],pos[maxn],n; 7 int main() { 8 while(~scanf("%d",&n)) { 9 memset(pos,-1,sizeof pos);10 bool flag = true;11 int sum = pos[0] = 0;12 for(int i = 1; i <= n; ++i) {13 scanf("%d",a + i);14 sum = (sum + a[i])%n;15 if(pos[sum] > -1 && flag) {16 printf("%d\n", i - pos[sum]);17 for(int j = pos[sum] + 1; j <= i; ++j)18 printf("%d\n",a[j]);19 flag = false;20 }21 pos[sum] = i;22 }23 }24 return 0;25 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4850893.html

你可能感兴趣的文章
第六章 堆排序 6.5 优先队列
查看>>
Linux搭建我的世界服务器
查看>>
数据库之范式
查看>>
译文 [ROM][多国语言][2015.06.11] Lenovo S750 (MTK6589) - andrea_d86-lenovos750-4.2.2
查看>>
租用游艇问题
查看>>
如何修改SharePoint 2010默认的任务通知邮件的格式?
查看>>
单用户模式下连接被占用定位spid
查看>>
Django JWT
查看>>
云推送注意(MSDN链接)
查看>>
条件编译解决AutoCAD多版本问题
查看>>
java的Integer与int的比较
查看>>
openstack安装文档
查看>>
正在改变世界的硅谷创业趋势
查看>>
No2_3.接口继承多态_Java学习笔记_多态
查看>>
[转] 体内湿气重怎样祛除
查看>>
C#多线程学习(五) 多线程的自动管理(定时器)
查看>>
第三次作业
查看>>
物体坐标to世界坐标
查看>>
上传图片进行预览
查看>>
Git学习笔记(二)
查看>>