CodeForces 485A Factory (抽屉原理)】的更多相关文章

A. Factory time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the begin…
Factory One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produ…
题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod m,那么再加上原来的,就总共有 a + a mod m 的details 啦,然后这个数就成了第二日开始的 details ,接着临一天结束要多生产(a + a mod m) mod m,第三日开始就变成 (a + a mod m) +  (a + a mod m) mod m .不断地重复重复重复…
题目链接:http://codeforces.com/contest/618/problem/F 题目: 题目大意: 有两个大小为 N 的可重集 A, B, 每个元素都在 1 到 N 之间. 分别找出 A 和 B 的一个子集, 使得这两个子集元素之和相等. 分别输出集合A和集合B的子集的个数以及子集中元素在原集合中的位置 N ≤ $10^6$ 题解: 首先我们证明一个结论,存在一组方案,满足两个子集在A中和在B中都是连续的一段 把两个集合看成两个数组,分别计算出前缀和sa,sb 对于每个i(0<…
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence…
转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内,然后让你求最小值 基本思路: 记sum[i]表示0 - i 的和对 p 取模的值. 1.如果k * p > n,那么与C2的做法一致,O(k*p*n)复杂度低于1e8. 2.如果k * p <= n 那么根据抽屉原理,必有至少k个sum[i]相同, 那么任意取k - 1个相同的 sum[i],记它…
题意: 给出两个数n,m,0<=n,m<=3000,输出n/m的循环小数表示以及循环节长度. 思路: 设立一个r[]数组记录循环小数,u[]记录每次的count,用于标记,小数计算可用 r[i]=n*10/m;n=n*10%10 直到n为0或u[n]!=0(找到循环节) 涉及到两个知识点:n/m的余数在0~m-1之间: 抽屉原理:循环次数最多不超过m+1次 具体见代码. //求循环节 #include<cstdio> #include<cstring> #define…
http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 813    Accepted Submission(s): 222 Problem Description We believe that every inh…
抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙的应用到,融合将问题一步步抽象转化来接近抽屉原理的原始模型,是用好抽屉原理的关键. 问题一:两个半径相等的圆盘上各有一个内接正2n边形,每个正2n边形的顶点有一半染上黄色,一般染上蓝色,将这一个圆盘放在另一个圆盘上并使得两个正2n边形的顶点均重合,这样得到2n对顶点,如果一对顶点中两个重合的顶点颜色…
/* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据抽屉原理: 因为有n个数,对n个数取余,如果余数中没有出现0,根据鸽巢原理,一定有两个数的余数相同, 如果余数出现0,自然就是n的倍数.也就是说,n个数中一定存在一些数的和是n的倍数. 本题的思路是从第一个数开始一次求得前 i(i <= N)项的和关于N的余数sum,并依次记录相应余数的存在状态,…