/*
POJ-2356 Find a multiple ----抽屉原理
Find a multiple
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4228 Accepted: 1850 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个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解,
随意输出一组即可。若不存在,输出 0。
题解:
首先必须声明的一点是本题是一定是有解的。原理根据抽屉原理:
因为有n个数,对n个数取余,如果余数中没有出现0,根据鸽巢原理,一定有两个数的余数相同,
如果余数出现0,自然就是n的倍数。也就是说,n个数中一定存在一些数的和是n的倍数。
本题的思路是从第一个数开始一次求得前 i(i <= N)项的和关于N的余数sum,并依次记录相应余数的存在状态,
如果sum == 0;则从第一项到第i项的和即满足题意。如果求得的 sum 在前边已经出现过,假设在第j(j<i)项出现
过相同的 sum 值,则从第 j+1 项到第i项的和一定满足题意。
*/
#include <iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 16000
int a[maxn];
int sum[maxn];
int main()
{
int i,j,k,n,flag;
while(scanf("%d",&n)!=EOF)
{
flag=false;
sum[]=;
for(i=; i<=n; i++)
{
scanf("%d",&a[i]);
} for(i=; i<=n; i++)
{
sum[i]=(sum[i-]+a[i])%n;
if(sum[i]==)
{ printf("%d\n",i);
for(k=; k<=i; k++)
printf("%d\n",a[k]);
break;
}
else
{
for(j=; j<i; j++)
{
if(sum[i]==sum[j])
{
printf("%d\n",i-j);
for(k=j+; k<=i; k++)
printf("%d\n",a[k]);
flag=true;
break;
}
}
}
if(flag)
break;
}
}
return ;
}

poj2356 Find a multiple的更多相关文章

  1. [POJ2356]Find a multiple 题解(鸽巢原理)

    [POJ2356]Find a multiple Description -The input contains N natural (i.e. positive integer) numbers ( ...

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

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

  3. [POJ2356] Find a multiple 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8776   Accepted: 3791   ...

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

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

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

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

  6. [poj2356]--Find a multiple ——鸽巢原理

    题意: 给定n个数,从中选取m个数,使得\(\sum | n\).本题使用Special Judge. 题解: 既然使用special judge,我们可以直接构造答案. 首先构造在mod N剩余系下 ...

  7. Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...

    Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...

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

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

  9. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

随机推荐

  1. 如何将dom4j的jar包放到java项目中

    ---恢复内容开始--- 如果你建的是java project项目的话,那就通过Myeclispe中的右键你的项目名称,选择build path ->config build path... 然 ...

  2. 当创建SDL工程发现“无法解析的外部符号 _SDL_main”出错

    当你创建一个新控制台程序,想调用SDL时,编译时发现如下出错: 1>------ 已启动生成: 项目: caipal, 配置: Debug Win32 ------1>  caipal.c ...

  3. postgresql与Oracle:空字符串与null

    空字符串:两个单引号,中间无空格等任何内容 在postgresql中,空字符串与null是不同的:而oracle中,空字符串与null等同.测试如下: postgresql中: postgres=# ...

  4. Python如何输出带颜色的文字

    print('\033[31m%s' % "这是前景色") 这是前景色 print('%s' % "这是前景色") 这是前景色 print('\033[1;31 ...

  5. Andriod4.2 Camera 架构与实现

    1.Camera架构包括客户端和服务端,他们之间的通信采用Binder机制实现. Camera的实现主要包括本地代码和Java代码两个层次: Camera本地框架: frameworks/native ...

  6. Zabbix server 3.2安装部署

    zabbix server 前提环境: CentOS 6 Lnmp php需要的包(bcmath,mbstring,sockets,gd,libxml,xmlwriter,xmlreader,ctyp ...

  7. C++ 项目经验总结:程序严谨性(一)

    作者:JK 时间:2015/09/24 特别说明:版权所有,转载请注明出处: 最近笔者在参与项目时,遇到了一些很奇特的问题,程序运行正常,产生的结果异常,程序功能是对当天的数据进行统计,数据里有可能有 ...

  8. 数据结构(Data Structures)

    一.List数据类型的方法 定义两个list,a和b:a=[1,2,3,4],b=[7,8,9,10] a.append(x)            在a的末尾附加x元素 a.extend(b)   ...

  9. 每天一个linux命令:【转载】nl命令

    nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...

  10. java面试题02

    1.JAVA内部使用的编码格式是(utf-8) 2. public class Threads2 implements Runnable { @Overridepublic void run() {S ...