POJ-2356 Find a multiple(DFS,抽屉原理)】的更多相关文章

Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7133 Accepted: 3122 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…
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…
从POJ 2356来体会抽屉原理的妙用= =! 题意: 给你一个n,然后给你n个数,让你输出一个数或者多个数,让这些数的和能够组成n: 先输出一个数,代表有多少个数的和,然后再输出这些数: 题解: 首先利用前缀和先预处理一下,然后如果sum[i]==0的话,很显然就直接输出i,然后接下来从第一位一直输出到第i位就行了 然后接下来直接用一个mod数组表示上一个答案为这个mod的时候的编号是多少 就是mod[sum[i]%n]=i; 然后判断一下if(mod[sum[i]%n]!=0)然后就直接从m…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6452   Accepted: 2809   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 a…
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…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6651   Accepted: 2910   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6535   Accepted: 2849   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
链接:传送门 题意:题意与3370类似 注意:注意输出就ok,输出的是集合的值不是集合下标 /************************************************************************* > File Name: poj2356.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年04月30日 星期日 12时24分2…
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至找到满足条件的数,注意最高位一定为1 假设 n=6  k即为当前所求的目标数,不满足条件则进一步递推 (i 为层数(深度),在解法二的优化中体现,此时可以不管) 1%6=1 (k=1) i=1 { (1*10+0)%6=4 (k=10) i=2 { (10*10+0)%6=4 (k=100) i=4…
抽屉原理: 形式一:设把n+1个元素划分至n个集合中(A1,A2,…,An),用a1,a2,…,an分别表示这n个集合对应包含的元素个数,则:至少存在某个集合Ai,其包含元素个数值ai大于或等于2.   形式二:设把nm+1个元素划分至n个集合中(A1,A2,…,An),用a1,a2,…,an表示这n个集合对应包含的元素个数,则:至少存在某个集合Ai,其包含元素个数值ai大于或等于m+1.   形式三:设把n个元素分为k个集合A1,A2,…,Ak,用a1,a2,…,ak表示这k个集合里相应的元素…
题目链接:http://poj.org/problem?id=2356 题目大意:给你n个数,要你从n个数选出若干个数,要求这若干个数的和是n的倍数,输出选择数的个数,以及相应的数. 解题思路: 以下摘自博客:https://www.cnblogs.com/pengwill/p/7367031.html 二.鸽巢原理(抽屉原理) 基本描述 桌子上有是个苹果,把这十个苹果放到九个抽屉里,无论怎么放,我们会发现至少会有一个抽屉里面至少放两个苹果.这一现象就是所说的“抽屉原理”. 更一般的表述:如果每…
Problem DescriptionThe 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…
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************************ Author :Running_Time Created Time :2015-8-2 14:21:51 File Name :POJ_1426.cpp *************************************************/ #include…
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] +…
/* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据抽屉原理: 因为有n个数,对n个数取余,如果余数中没有出现0,根据鸽巢原理,一定有两个数的余数相同, 如果余数出现0,自然就是n的倍数.也就是说,n个数中一定存在一些数的和是n的倍数. 本题的思路是从第一个数开始一次求得前 i(i <= N)项的和关于N的余数sum,并依次记录相应余数的存在状态,…
题意:给你N个数,从中取出任意个数的数 使得他们的和 是 N的倍数: 在鸽巢原理的介绍里面,有例题介绍:设a1,a2,a3,……am是正整数的序列,试证明至少存在正数k和l,1<=k<=l<=m,是的和ak+ak+1+……+al是m的倍数,接下来开始证明: 构造一个序列s1=a1,s2=a1+a2,……,sm=a1+a2+……+am,那么会产生两种可能: 1:若有一个sn是m的倍数,那么定理成立: 2:假设上述的序列中没有任何一个元素是m的倍数,令rh ≡ sh mod m;其中h=1,…
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…
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…
http://poj.org/problem?id=2356 方法一:  鸽巢原理 解题思路:  n个数,,依次求其s[0],s[1],s[2],s[3].....s[n]  然后对 n取模,,必然会得到n+1个结果,,这n+1个结果放到0---n-1,这n个盒子中,必然会有重复的,所以这两个重复的之间,必然就是所求的结果. #include <iostream> #include<cstring> using namespace std; int n; ]; ]; ]; int…
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…
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may as…
POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Accepted: 10613   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representati…
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…
题意: 给出两个数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…
POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u   Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k…
抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙的应用到,融合将问题一步步抽象转化来接近抽屉原理的原始模型,是用好抽屉原理的关键. 问题一:两个半径相等的圆盘上各有一个内接正2n边形,每个正2n边形的顶点有一半染上黄色,一般染上蓝色,将这一个圆盘放在另一个圆盘上并使得两个正2n边形的顶点均重合,这样得到2n对顶点,如果一对顶点中两个重合的顶点颜色…
1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍数. 例如:N = 8,数组A包括:2 5 6 3 18 7 11 19,可以选2 6,因为2 + 6 = 8,是8的倍数.   Input 第1行:1个数N,N为数组的长度,同时也是要求的倍数.(2 <= N <= 50000) 第2 - N + 1行:数组A的元素.(0 < A[i] &…
传送门 首先,选取子集的限制太宽了,子集似乎只能枚举,不是很好做.考虑加强限制条件:将"选取子集"的限制变为"选取子序列"的限制.在接下来的讨论中我们将会知道:将限制控制得更紧,问题也一定会有解. 现在我们需要求\(A,B\)的两个子序列,满足两者的和相等.显然可以前缀和,然后就不会做了qwq 考虑下面的算法:假定\(\sum\limits_{a \in A} a < \sum\limits_{b \in B} b\)(如果相等直接全选),设序列\(A\)前缀…
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1,根据抽屉原则,当计算m+1次时至少存在一个余数相同,即为循环节:存储余数和除数,输出即可. 上面是我查到的,现在让我解释一下: 比如5/43,先是要模拟除法运算,第一步50/43 余7;第二步,70/43 于27... 这样一直取余下去,肯定不会超过43次,就会有余数相同的情况,有相同情况就是找到循环节了.…
题目传送: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…