Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6452   Accepted: 2809   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

5
1
2
3
4
1

Sample Output

2
2
3
 /*这题在于对抽屉原理的应用,输入一个数N,然后有N行,每一行输入一个数,*/
/*求是否存在连续和能够整除N的数,并且输出该数的个数以及连续数*/
/*
抽屉原理:主要是用来求数列的某一段连续和能够整除该数列个数的问题;
先累每一个数,记录在Sum中,设i>j,则sum[i]-sum[j]则表示位置i到位置j这一段区间的和,
题目既可以简化为求(sum[i]-sum[j])%N==0的满足条件即可
所以设q,p(倍数),r1,r2(余数)为整数,
sum[i]=q*N+ri,sum[i]=p*N+rj;
ri=Sum[i]%N (ri为余数)
(sum[i]-sum[j])=>(q*N+ri)-(p*N+rj)=>(q-p)*N+(ri-rj)
既为:(sum[i]-sum[j])%N==0=>((q-p)*N+(ri-rj))%N==0
=>(ri-rj)%n==0=>ri=rj可以使得等式成立,可满足条件;
所以只需要求解存在两个ri和rj相等,就可以知道,该段位置从i+1累加到j能够被N整除
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int Num[]; /*记录输入数据*/
int Sum[]; /*记录数据的累加和*/
int Sign[]; /*记录该数据累加和取余后的情况,sign[i],0<=i<N*/
int ID[]; /*ID[i]表示该余数是否被出现过了,记录每一个余数第一次产生i的位置,且ID[0]=0*/
int Begin,End,Flat,i,N; /*Flat标记是否完成任务*/
while(scanf("%d",&N)!=EOF)
{
memset(Sum,,sizeof(Sum));
memset(ID,-,sizeof(ID)); /*因为ID存放的是该数的位置,需要初始化为-1,*/
ID[]=;/*记得标记初始位置的*/
for(i=,Flat=;i<=N;i++)
{
scanf("%d",&Num[i]);
Sum[i]=Sum[i-]+Num[i]; /*求累加和*/
Sign[i]=Sum[i]%N; /*求累加和的余数*/
if(ID[Sign[i]]>=&&Flat) /*判断该位置是否被使用过,且是否完成任务*/
{
Begin=ID[Sign[i]]; /*记录开始点*/
End=i; /*记录结束点*/
Flat=;
}
else if(Flat)
ID[Sign[i]]=i; /*如果该余数未被产生,则记录下该余数第一次出现的位置*/
}
printf("%d\n",End-Begin);
for(i=Begin+;i<=End;i++)
{
printf("%d\n",Num[i]);
} }
return ;
}

POJ- Find a multiple -(抽屉原理)的更多相关文章

  1. POJ 2356 Find a multiple 抽屉原理

    从POJ 2356来体会抽屉原理的妙用= =! 题意: 给你一个n,然后给你n个数,让你输出一个数或者多个数,让这些数的和能够组成n: 先输出一个数,代表有多少个数的和,然后再输出这些数: 题解: 首 ...

  2. poj2356 Find a multiple(抽屉原理|鸽巢原理)

    /* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据 ...

  3. POJ2356 Find a multiple 抽屉原理(鸽巢原理)

    题意:给你N个数,从中取出任意个数的数 使得他们的和 是 N的倍数: 在鸽巢原理的介绍里面,有例题介绍:设a1,a2,a3,……am是正整数的序列,试证明至少存在正数k和l,1<=k<=l ...

  4. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Every year there is the same problem at Halloween: Each neighbour is only willing t ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  7. Find a multiple POJ - 2356 (抽屉原理)

    抽屉原理: 形式一:设把n+1个元素划分至n个集合中(A1,A2,…,An),用a1,a2,…,an分别表示这n个集合对应包含的元素个数,则:至少存在某个集合Ai,其包含元素个数值ai大于或等于2. ...

  8. poj 2356 (抽屉原理)

    题目链接:http://poj.org/problem?id=2356 题目大意:给你n个数,要你从n个数选出若干个数,要求这若干个数的和是n的倍数,输出选择数的个数,以及相应的数. 解题思路: 以下 ...

  9. POJ-2356 Find a multiple(DFS,抽屉原理)

    Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7133 Accepted: 3122 Speci ...

随机推荐

  1. c++实现快速排序详细分析

    快速排序坑挺多的,今天有空记录一下自己的实现,并加上详细的注释和举例 #include<iostream> using namespace std; int partion(int num ...

  2. Angularjs directive全面解读(1.4.5)

    说到Angularjs directive即指令,可以这么说Angularjs的灵魂就是指令,学会Angularjs指令那么你的Angularjs的武功就修炼了一半了,当然这只是鄙人的一点点独到见解, ...

  3. asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)

    项目使用的MVC4,.net 4.5 Nuget安装最新的autofac,一直提示不支持.net 4.5.没办法了,最后用Nuget控制台安装的老版本.因为我使用的是MVC4,所以直接安装的是auto ...

  4. 分布式版本控制系统Git-----6.Git 常见命令一览表

    说明/备注 命令 备注 保存更新 git add [-i] -i 逐个确认 检查更新 git status 提交更新 git commit [-a] -m "<更新说明>&quo ...

  5. Linux系统编程初探系列之一:文件编程

    系统函数 int creat(const char* filename,mode_t mode) filename:需要创建的文件名(包含路径,缺省为当前路径) mode:创建模式 常见的创建模式有: ...

  6. hdu 1531 King

    首先吐槽一下这个题目的题意描述,我看了半天才明白. 下标全部都是乱标的!!!!出题者能不能规范一点下标的写法!!!! 差分约束系统 #include<cstdio> #include< ...

  7. GOPS 2016全球运维大会 • 北京站概况

    GOPS 2016全球运维大会上海站已圆满落幕,错过上海站的朋友或许会感到一些遗憾,但是不用担心,在12月16日,GOPS 2016全球运维大会 • 北京站将隆重召开,错过上海在的朋友可以赶上北京站哦 ...

  8. Spring Security(09)——Filter

    目录 1.1     Filter顺序 1.2     添加Filter到FilterChain 1.3     DelegatingFilterProxy 1.4     FilterChainPr ...

  9. 微信支付错误两个问题的解决:curl出错,错误码:60

    如下是运行微信支付测试代码时出错代码: Warning: curl_setopt() expects parameter 2 to be long, string given in D:\wwwroo ...

  10. img 鼠标滑上后图片放大,滑下后图片复原

    <style type="text/css">img{ -webkit-transition: ease .2s; transition: ease .2s; -web ...