Find a multiple
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6535   Accepted: 2849   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

Source

Ural Collegiate Programming Contest 1999
 
鸽巢定理,注意代码实现的细节,0MS ac
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 10010 struct Node
{
int x,y,s; //下标,余数,前缀和
bool operator <(const Node &t)const
{
if(y!=t.y) return y<t.y;
return x<t.x;
}
}p[N]; int main()
{
int n;
int flag;
int a[N];
while(scanf("%d",&n)!=EOF)
{
flag=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
p[i].s=p[i-].s+a[i];
p[i].x=i;
p[i].y=p[i].s%n;
if(!flag && p[i].y==)
{
flag=;
printf("%d\n",i);
for(int j=;j<=i;j++) printf("%d\n",a[j]);
}
}
if(flag) continue;
sort(p+,p+n+);
for(int i=;i<=n;i++)
{
if(p[i].y==p[i-].y)
{
int &l=p[i-].x;
int &r=p[i].x;
printf("%d\n",r-l);
for(int j=l+;j<=r;j++) printf("%d\n",a[j]);
break;
}
}
}
return ;
}

[POJ 2356] Find a multiple的更多相关文章

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

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

  2. POJ 2356 Find a multiple 抽屉原理

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

  3. poj 2356 Find a multiple(鸽巢原理)

    Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that n ...

  4. poj 2356 Find a multiple【鸽巢原理 模板应用】

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6651   Accepted: 2910   ...

  5. POJ 2356 Find a multiple( 鸽巢定理简单题 )

    链接:传送门 题意:题意与3370类似 注意:注意输出就ok,输出的是集合的值不是集合下标 /***************************************************** ...

  6. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  7. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  8. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

  9. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

随机推荐

  1. call callb callp区别

    对于刚刚接触ILE模式开发的初级菜鸟而言,想要搞清楚这三者的区别还是有点难度的.网上虽然一些帖子对这三者进行了比较,但是这些帖子或是语焉不详,或是高度概括.对于老鸟来说或许已经足矣,但是对于初级菜鸟而 ...

  2. WPF多线程演示

    WPF中的几种处理线程的工作方式: 1.简单的DispatcherTimer类似Timer控件 2.需要处理UI同步时,Dispatcher DispatcherOpertion 3.增强的Threa ...

  3. Who needs an architect?---Martin Fowler

    英文及译文下载链接:http://pan.baidu.com/share/link?shareid=163291504&uk=1428554614 1.文章主题总结 首先我们从文章的几个小标题 ...

  4. Datatables中文API——回调函数

    fnCookieCallback:还没有使用过 $(document).ready(function () { $('#example').dataTable({ "fnCookieCall ...

  5. DataTableExtensions.AsEnumerable 方法

    在下面的示例中,DisplayProducts 方法接收一个数据表,其中包含名为 ProductName一个 DataColumn,提取 ProductName 值,然后输出值. using Syst ...

  6. Nhibernate 多对多级联删除

    在网上找到的方法:查看这里 //-------------------------------------Article.hbm.xml-------------------------------- ...

  7. java接口与继承

    class Grandparent { public Grandparent() { System.out.println("GrandParent Created."); } p ...

  8. properties配置文件中文乱码解决方法

    方法1   properties文件的格式一般为: ROOT=http://localhost:8080/BNCAR2/ ROOTPATH=E:/ws2/BNCAR2/rel/ MALL_PARTS_ ...

  9. Discuz模版与插件 安装时提示“对不起,您安装的不是正版应用...”解决方法

    关于出现“对不起,您安装的不是正版应用..”的解决办法 有些插件和风格在安装时出现不能安装的现象,出现以下提示:       对不起,您安装的不是正版应用,安装程序无法继续执行       点击这里安 ...

  10. Qt之界面数据存储与获取(使用setUserData()和userData())

    在GUI开发中,往往需要在界面中存储一些有用的数据,这些数据可以来配置文件.注册表.数据库.或者是server. 无论来自哪里,这些数据对于用户来说都是至关重要的,它们在交互过程中大部分都会被用到,例 ...