CodeForces485A——Factory(抽屉原理)
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 produce (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m).
Given the number of details a on the first day and number m check if the production stops at some moment.
Input
The first line contains two integers a and m (1 ≤ a, m ≤ 105).
Output
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Sample test(s)
Input
1 5
Output
No
Input
3 6
Output
Yes
题目大意:
一个工厂,仓库中有X个产品,那么当天就生产X mod M个产品。给一个A代表仓库中的产品个数,问是否存在工厂停工的一天。即X mod M = 0。
解题思路:
错误思路:
当时拿到第一组样例进行验算发现:
第一天 1 5 生产1件
第二天 2 5 生产2件
第三天 4 5 生产4件
第四天 8 5 生产3件
第五天 11 5 生产1件
第六天 12 5 生产2件
可以看到每天的生产数每4天一循环。
X mod M的结果属于[0,M-1]。那么最多要是在M天以内没有出现 X mod M==0 的情况,就不会在出现了。(根据抽屉原理第M+1次必会重复,但是若出现0就结束判断,只需判断循环M次会不会出现0即可)
Code:
/*************************************************************************
> File Name: CF485A.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年11月06日 星期四 00时47分17秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int t=b;
while (t--)
{
if ((a+a%b)%b==)
{
printf("Yes");
return ;
}
else
a=(a+a%b)%b;
}
printf("No");
return ;
}
CodeForces485A——Factory(抽屉原理)的更多相关文章
- CodeForces 485A Factory (抽屉原理)
A. Factory time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- uva202:循环小数(循环节+抽屉原理)
题意: 给出两个数n,m,0<=n,m<=3000,输出n/m的循环小数表示以及循环节长度. 思路: 设立一个r[]数组记录循环小数,u[]记录每次的count,用于标记,小数计算可用 r ...
- hdu 3303 Harmony Forever (线段树 + 抽屉原理)
http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...
- 《Mathematical Olympiad——组合数学》——抽屉原理
抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙 ...
- poj2356 Find a multiple(抽屉原理|鸽巢原理)
/* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据 ...
- POJ- Find a multiple -(抽屉原理)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6452 Accepted: 2809 Special Judge D ...
- 51nod 1103 N的倍数(抽屉原理)
1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍 ...
- CF618F Double Knapsack 构造、抽屉原理
传送门 首先,选取子集的限制太宽了,子集似乎只能枚举,不是很好做.考虑加强限制条件:将"选取子集"的限制变为"选取子序列"的限制.在接下来的讨论中我们将会知道: ...
- poj 2356 (抽屉原理)
题目链接:http://poj.org/problem?id=2356 题目大意:给你n个数,要你从n个数选出若干个数,要求这若干个数的和是n的倍数,输出选择数的个数,以及相应的数. 解题思路: 以下 ...
随机推荐
- Android -- 获取摄像头帧数据解码
由于Android下摄像头预览数据只能 ImageFormat.NV21 格式的,所以解码时要经过一翻周折. Camera mCamera = Camera.open(); Camera.Param ...
- 20145103 《Java程序设计》第2周学习总结
20145103 <Java程序设计>第2周学习总结 教材学习内容总结 在第三章主要学习了Java语言中的类型及其变量主要类型为:整数(1字节的byte,2字节的short,4字节的int ...
- 简单的C语言小学四则运算设计
题目:设计一个简单的四则运算编辑器 思路:我使用的是C语言编程,看到题目首先要随机出3个随机数,其中两个为100以内的随机数(a,b),一个为0~3的随机数(k). k值的变化使得+ - * /的变化 ...
- 使用sqlserver日期函数获取当前日期
使用sqlserver日期函数中的getdate()可以获取当现的日期,下面就将为您介绍这种使用sqlserver日期函数获取当前日期的方法,供您参考,希望对您学习sqlserver日期函数有所启迪. ...
- string::rfind
该函数返回目标字符串(key)在源字符串中最后一次匹配的位置 如果没有找到匹配的位置则返回string::npos,是一个无符号整形数字,可以打印看看 //// string::rfind #incl ...
- 作用域+闭包+this理解
函数预解析过程 函数会覆盖同名变量 也就是var 他的优先级高 如果是同名函数则后者覆盖前者 逐行解读代码的时候 表达式 和参数 会改变预解析仓库里面的值..也就是表达式能干掉函数 ...
- LightOJ 1140 How Many Zeroes
题意:写出一个给定区间的每个数,求出一共写了多少个零. 解法:数位DP,定义dp[len][flag][num]:len的定义为数位的长度,flag定义为前导0和没有前导0的两种状态,num定义为写的 ...
- 【BZOJ】【1010】【HNOI2008】玩具装箱Toy
DP/斜率优化 根据题目描述很容易列出动规方程:$$ f[i]=min\{ f[j]+(s[i]-s[j]+i-j-1-L)^2 \}$$ 其中 $$s[i]=\sum_{k=1}^{i} c[k] ...
- C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(611,5): error MSB
project options, linker, manifest, Generate Manifest-> NO. 项目->属性->链接器->清单文件->生成清单 改 ...
- Apple Remote Push Notifications
1.帮助文档参考: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/Remote ...