UVA 11237 - Halloween treats(鸽笼原理)】的更多相关文章

11237 - Halloween treats option=com_onlinejudge&Itemid=8&page=show_problem&category=516&problem=2178&mosmsg=Submission+received+with+ID+13856428" target="_blank" style="">题目链接 题意:有c个小伙伴,n个房子(c <= n).每一个房子…
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/37612503 题目链接:uva 11237 - Halloween treats 题目大意:有c个小孩要到邻居家去要糖果.有n户邻居.每户邻居仅仅会提供固定数量的糖果,熊孩子们为了不发生冲突,决定将取来的糖果平均分配,问说取那几家邻居的糖果能够做到平均分配.注意n ≥ c. 解题思路:抽屉原理.求出序列的前缀和,有n个,将前缀和对c取模后.依…
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…
Halloween treats 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…
[POJ3370]&[HDU1808]Halloween treats 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…
UVA 10620 - A Flea on a Chessboard 题目链接 题意:给定一个跳蚤位置和移动方向.如今在一个国际象棋棋盘上,左下角为黑格,一个格子为s*s,推断是否能移动到白格子.问要移动多少次才干到白格,边界不算白格. 思路:利用鸽笼原理落在黑格子和边界上的一共同拥有(s + 1)^2个点,也就是说.假设形成循环,周期肯定在这之内.所以能够不断去模拟跳格子,直到踩到白格,或者踩到之前落到过的黑格就结束 只是事实上还有更优的方法,由于跳蚤跳跃路径为直线,观察下能够发现假设能够到白…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448   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…
Halloween treats 和POJ2356差点儿相同. 事实上这种数列能够有非常多,也能够有不连续的,只是利用鸽巢原理就是方便找到了连续的数列.并且有这种数列也必然能够找到. #include <cstdio> #include <cstdlib> #include <xutility> int main() { int c, n; while (scanf("%d %d", &c, &n) && c) { i…
Halloween treats Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1097    Accepted Submission(s): 435Special Judge Problem Description Every year there is the same problem at Halloween: Each neig…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7143   Accepted: 2641   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…
题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<10^5,点的坐标值m<10^5. 题解:表面上这道题复杂度是O(n^2)会超时的,而实际上这些坐标差绝对值的和最大是2*10^5,所以复杂度不是O(n^2),而是O(min(n^2,m)),这就是著名的鸽笼原理. #include <iostream> #include <cstdio…
Problem G. Generators Input file: generators.in Output file: generators.outLittle Roman is studying linear congruential generators — one of the oldest and best known pseudorandom number generator algorithms. Linear congruential generator (LCG) starts w…
描述 http://poj.org/problem?id=1065 木棍有重量 w 和长度 l 两种属性,要使 l 和 w 同时单调不降,否则切割机器就要停一次,问最少停多少次(开始时停一次). Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21277   Accepted: 9030 Description There is a pile of n wooden sticks. The le…
中学就听说过抽屉原理,可惜一直没机会见识,现在这题有鸽笼原理的结论,但其实知不知道鸽笼原理都可以做 先总结一下鸽笼原理: 有n+1件或n+1件以上的物品要放到n个抽屉中,那么至少有一个抽屉里有两个或两个以上物品. 如果你知道这个结论: a1,a2,a3...am是正整数序列,至少存在整数k和r,1<=k<r<=m,使得ak+a(k+1)+...+a(r)是m的倍数. 证明比较简单: Sk表示前k个数之和, (1)若Sk%m==0,前k个数就是m的倍数 (2)如果Sn与St模m同余,那么从…
关于鸽笼原理的知识看我写的另一篇博客 http://blog.csdn.net/u011026968/article/details/11564841 (需要说明的是,我写的代码在有答案时就输出结果了,但OJ也是从文件读入,所以乍一看我的好像在没输入完就有结果了,但OJ不知道,其实我是直接拿poj3370的代码AC的,32MS,O(∩_∩)O) 直接贴代码 #include<cstdio> #include<cstring> using namespace std; #define…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8565   Accepted: 3111   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…
题目链接  Points Inside A Polygon 题意  给定一个$n$个点的凸多边形,求出$[ \frac{n}{10}]\ $个凸多边形内的整点. 把$n$个点分成$4$类: 横坐标奇,纵坐标奇 横坐标奇,纵坐标偶 横坐标偶,纵坐标奇 横坐标偶,纵坐标偶 根据鸽笼原理,这$4$类点中至少有一类点数目不小于$[ \frac{n}{4}]\ $ 每一个类别中,每两个点的中点肯定为整点,并且当这两个点不在凸多边形上相邻的时候, 他们一定在凸多边形内. 那么把这$4$个类别里面的点分别处理…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1393 正解一眼看出来的应该是鸽笼原理.记录每个位置的前缀和,就是dp[i][1]表示前i个数中,1的个数.dp[i][0]同理. 然后计算出每一个位置的dp[i][1] - dp[i][0],如果和前面的出现相同,那么这一段就是贡献. 也可以从化简dp公式来看. 也是一样的都dp[i][0] && dp[i][1] 那么设区间为be, en 如果要相同,则需要dp…
To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a1,a2,-,an. Help Kuroni to calculate ∏1≤i<j≤n|ai−aj|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏1≤i<…
基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: 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…
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1808 Problem 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, s…
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…
链接:传送门 题意:万圣节到了,有 c 个小朋友向 n 个住户要糖果,根据以往的经验,第i个住户会给他们a[ i ]颗糖果,但是为了和谐起见,小朋友们决定要来的糖果要能平分,所以他们只会选择一部分住户索要糖果,这样糖果恰好可以平分又不会剩下,输出索要糖果的用户编号.如果没有任何一组住户给的糖果总数能够平分,则输出 "no sweets" .SPJ( 意味着答案不唯一 ) 思路: 简单鸽巢原理题目,可以将问题转化成 给出一个正整数序列A1,A2, ... ,An ,求有没有整数 l 和…
题目链接: id=3370">http://poj.org/problem?id=3370 http://acm.hdu.edu.cn/showproblem.php?pid=1808 题目大意: 给你两个整数C和N,再给你N个正数的序列.从中找到若干数,使得其和刚好是 C 的倍数. 输出这些数的序号. 解题思路: 典型的抽屉原理. Sum[i]为序列中前 i 项的和.则有两种可能: 1.若有 Sum[i] 是 C 的倍数.则直接输出前 i 项. 2.假设没有不论什么的 Sum[i] 是…
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 late. To avoi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1205 题目解析:开始没看清题,WA了一发,以为只要最大的次大的差2就是NO,后来仔细看过之后才发现,,,,这题要用隔板法来求解 1.把某种糖果看做隔板,如果某种糖果有n个,那么就有n+1块区域,至少需要n-1块其他种糖果才能使得所有隔板不挨在一块..也就是说能吃完这种糖果.至少需要其他种类糖果n-1块..(鸽巢原理) 2.数量最多的糖果(隔板)可以构造最多的空间,如果这种糖果有maxn个....那么…
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1,根据抽屉原则,当计算m+1次时至少存在一个余数相同,即为循环节:存储余数和除数,输出即可. 上面是我查到的,现在让我解释一下: 比如5/43,先是要模拟除法运算,第一步50/43 余7;第二步,70/43 于27... 这样一直取余下去,肯定不会超过43次,就会有余数相同的情况,有相同情况就是找到循环节了.…
题目链接:hdu_5762_Teacher Bo 题意: 给你n个点,问你能否找到两对点的曼哈顿距离相等 题解: 最开始看到这题,看数据以为要向nlogn的复杂度发展,结果经验误导了自己,我们仔细观察可以发现,题目给的点的坐标范围为0~1e5,说明所有的点对的曼哈顿距离的种数不会超过2*m+1,意思就是n个点的曼哈顿距离的范围为0~200000,所以如果点对的个数大于2*m+1,那么必定会有重复的曼哈顿距离,也就是由两对点的曼哈顿距离相同,所以特判后直接暴力,复杂度不超过10W. #includ…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2858 题意:给你n天须要穿的衣服的样式,每次能够套着穿衣服,脱掉的衣服就不能再用了(能够再穿),问至少要带多少条衣服才干參加全部宴会 分组背包模板题: dp[i][j];若第j件穿,dp[i][j]=d[i][j-1]+1; 若不穿.则能够想到.i到j-1区间内必须…
吃糖果Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 47659    Accepted Submission(s): 13626 Problem DescriptionHOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样:可是G…