poj 2356 Find a multiple(鸽巢原理)】的更多相关文章

链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户索要糖果,这样糖果恰好可以平分又不会剩下,输出索要糖果的用户编号.如果没有任何一组住户给的糖果总数能够平分,则输出 "no sweets" .SPJ( 意味着答案不唯一 ) 思路: 简单鸽巢原理题目,可以将问题转化成 给出一个正整数序列A1,A2, ... ,An ,求有没有整数 l 和…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8776   Accepted: 3791   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
题意: 给定n个数,从中选取m个数,使得\(\sum | n\).本题使用Special Judge. 题解: 既然使用special judge,我们可以直接构造答案. 首先构造在mod N剩余系下的前缀和. \[sum_i = (a_i + sum_{i-1}) mod n\] 剩余系N的完系中显然共有N-1个元素,我们有N个前缀和. 根据鸽巢原理,一定有\(sum_j = sum_i\) 所以这样构造是可行的. TRICK 具体实现的时候用了一个技巧: 从前往后扫描sum数组,记录一个po…
Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too l…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that numbers . This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task <= few <= N ) so that the su…
POJ 2356: 题目大意: 给定n个数,希望在这n个数中找到一些数的和是n的倍数,输出任意一种数的序列,找不到则输出0 这里首先要确定这道题的解是必然存在的 利用一个 sum[i]保存前 i 个数的和对n的取模 sum[0] = 0; 那么sum[0] ~ sum[n]有n+1个数据,这些数据的范围都是 0~n , 要是存在 sum[i] = 0,那么输出前 i 个数据即可 要是不存在那根据鸽巢原理可以说明必然能找到一个 sum[i] = sum[j]  ,那么说明 (sum[i+1] +…
参考:https://www.cnblogs.com/ACShiryu/archive/2011/08/09/poj2356.html 鸽巢原理??? 其实不用map但是习惯了就打的map 以下C-c自参考博客: 我们可以依次求出a[0],a[0]+a[1],a[0]+a[1]+a[2],......,a[0]+a[1]+a[2]...+a[n]: 假设分别是sum[0],sum[1],sum[2],......,sum[n] 如果在某一项存在是N的倍数,则很好解,即可直接从第一项开始直接输出答…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
[POJ2356]Find a multiple 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 w…