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

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

Find a multiple
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4642   Accepted: 2020   Special Judge

Description

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

  考察点: 鸽巢原理
#include 
#include
#include
int sum[11000],a[11000],pt[11000];int main(){ int i,j,n,m,s,t,key; while(scanf("%d",&n)!=EOF) { key=-1; memset(sum,0,sizeof(sum)); memset(pt,0,sizeof(pt)); for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; if(sum[i]%n==0) { key=i; } } if(key!=-1) { printf("%d\n",key); for(i=1;i<=key;i++) { printf("%d\n",a[i]); } continue; } for(i=1;i<=n;i++) { m=sum[i]%n; if(!pt[m]) { pt[m]=i; }else { break; } } printf("%d\n",i-pt[m]); for(j=pt[m]+1; j<=i ;j++) { printf("%d\n",a[j]); } } return 0;}

 

转载地址:http://ojnna.baihongyu.com/

你可能感兴趣的文章
struts2 API chm帮助文档生成介绍说明(转)
查看>>
数据字典统一管理,动态下拉框
查看>>
汽车常识全面介绍 - 引擎详论
查看>>
枚举类型、结构体和类的区别
查看>>
AngularJS使用ngMessages进行表单验证
查看>>
TCP编程的迷惑
查看>>
redis专题--slow log详解
查看>>
9-0-查找表-查找-第9章-《数据结构》课本源码-严蔚敏吴伟民版
查看>>
thinkphp整合系列之短信验证码、订单通知
查看>>
fsimage 和 edits log
查看>>
遍历json对象---Java
查看>>
从头开始搭建一个Spring boot+RabbitMQ环境
查看>>
bash编程 将一个目录里所有文件存为一个array 并分割为三等分——利用bash array切片...
查看>>
自己动手开发IOC容器
查看>>
hdparm
查看>>
[LeetCode] Best Time to Buy and Sell Stock
查看>>
《Flask Web开发——基于Python的Web应用开发实践》一字一句上机实践(上)
查看>>
C++11学习
查看>>
【java】java工具类StringUtils,org.apache.commons.lang3.StringUtils
查看>>
WPF太阳、地球、月球运动轨迹模拟
查看>>