/*
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. Gradle2.0用户指南翻译——第二章. 概述

    翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2 ...

  2. 产生num个不重复的随机数组

    createDiffRandom : function (from,to,num) { // 产生num个不重复的随机数组 var arr=[],json={}; // 随机数数组 , 标记json对 ...

  3. Webdynpro ABAP 简单剖析

    众所周知,WEBDYNPRO是今天来SAP主推的一个面向WEB的MVC编程框架,接触过J2EE的朋友都不会对MVC这种设计模式陌生,WEBDYNPRO ABAP的基本设计思路和很多著名的面向互联网的M ...

  4. 【剑指offer】连续子数组的最大和,C++实现

    原创博文,转载请注明出处!本题牛客网地址 博客文章索引地址 博客文章中代码的github地址 # 题目       输入一个整形数组,数组里有正数也有负数.数组中的一个或连续多个整数组成一个子数组.求 ...

  5. sockaddr和sockaddr_in的区别

    struct sockaddr和struct sockaddr_in这两个结构体用来处理网络通信的地址. 在各种系统调用或者函数中,只要和网络地址打交道,就得用到这两个结构体. 网络中的地址包含3个方 ...

  6. 每天一个linux命令(目录文件操作):【转载】Linux 目录结构

    对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统至关重要,下面 ...

  7. JSON和JSONP简单总结

    jsonp和json的区别,原理,在jquery中的使用 http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.h ...

  8. 前端(六):JavaScript面向对象之宿主对象

    宿主对象即浏览器提供的对象,主要包括DOM对象和BOM对象. 一.DOM源起 1.SGML.XML和XHTML SGML(标准通用标记语言)是定义使用标签来表示数据的标记语言的语法. - 标签由一个小 ...

  9. Promise详解

    前言 && 基础概念 Promise 是解决 JS 异步的一种方案,相比传统的回调函数,Promise 能解决多个回调严重嵌套的问题. Promise 对象代表一个异步操作,有三种状态 ...

  10. 使用distillery 构建专业的 phoenix 项目软件包

    备注:     首先需要安装 elixir 环境   1. 基本项目说明 参考项目: https://github.com/rongfengliang/phoenix-rest-demo 2. 项目说 ...