HDU 1014 Uniform Generator(最大公约数,周期循环)
#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void)
{
int s,m,i;
/*int seed=0;
int a[10005]={0};
//memset(a,0,sizeof(a));*/
while(scanf("%d%d",&s,&m)!=EOF);
{
int seed=0;
int a[10005]={0};
while(!a[seed])//
{
a[seed]=1;//若本位0,变换标志位为1,直到出现循环到头,标志过了的就跳出
seed=(seed+s)%m;//seed根据随机数公式变化
}
for(i=0;i<m;i++)//范围0-m
{
if(a[i]==0)//只要有没出现在0~m-1的数就不好
{
printf("%10d%10d Bad Choice\n\n",s,m);
break;
}
}
if(i==m){ //跳出循环后,刚好以m为周期
printf("%10d%10d Good Choice\n\n",s,m);
}
}
}
#include<iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
if(a<b)
swap(a,b);
return b?gcd(b,a%b):a;
}
int main()
{
int i,j,s,m;
while(~scanf("%d%d",&s,&m))
{
if(gcd(s,m)==1)
{
printf("%10d%10d Good Choice\n\n",s,m);
}
else
{
printf("%10d%10d Bad Choice\n\n",s,m);
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h> int main()
{
int step,mod,seed,count;
while(scanf("%d%d",&step,&mod)!=EOF)
{
seed=0,count=1;
do
{
seed=(seed+step)%mod;
count++;
}while(seed!=0);
count--;
printf("%10d%10d ",step,mod);
if(count==mod)
printf("%s\n","Good Choice");
else
printf("%s\n","Bad Choice");
printf("\n");
}
system("pause");
return 0;
}
#include<iostream>
using namespace std; int main()
{
int s,m,x,c;
while(scanf("%d%d",&s,&m)!=EOF)
{
x=c=0;
do
{
x=(x+s)%m;
++c;
} while(x!=0); if(c==m)
printf("%10d%10d Good Choice\n\n",s,m);
else
printf("%10d%10d Bad Choice\n\n",s,m);
}
return 0;
}
HDU 1014 Uniform Generator(最大公约数,周期循环)的更多相关文章
- HDU 1014 Uniform Generator(模拟和公式)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...
- HDU 1014 Uniform Generator【GCD,水】
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014:Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014 Uniform Generator(题解)
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014 Uniform Generator 欧几里得
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...
- hdu 1014.Uniform Generator 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...
- HDU 1014 Uniform Generator 题解
找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...
- hdu 1014 Uniform Generator 数论
摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...
随机推荐
- 51nod 1565模糊搜索(FFT)
题目大意就是字符串匹配,不过有一个门限k而已 之前有提到过fft做字符串匹配,这里和之前那种有些许不同 因为只有A,C,G,T四种字符,所以就考虑构造4个01序列 例如,模板串a关于'A'的01序列中 ...
- [洛谷P2590][ZJOI2008]树的统计
题目大意:一棵树,支持三个操作, $CHANGE\;u\;t:$ 把结点$u$的权值改为$t$ $QMAX\;u\;v:$ 询问从点$u$到点$v$的路径上的节点的最大权值 $QSUM\;u\;v:$ ...
- Noip2016滚粗记QAQ
day1 t1 XBG #include<map> #include<cstdio> #include<string> #include<string.h&g ...
- ext radiogroup如何取值和设值
var radios = Ext.create('Ext.form.Panel', { title: 'RadioGroup Example', width: 300, height: 125, bo ...
- Ubuntu下使用find / -name aaa* 提示“find: 路径必须在表达式之前: XXXX”
在使用find命令查找文件时,出现了如题所示的错误提示,因为之前都是这样用的,也没出过错,这次语法都是一样的居然不行了,很是纳闷. 后来了解到如下的情况: 如果当前所在目录存在要查找的目标文件时会出现 ...
- ZooKeeper Watcher注意事项
zookeeper watch的定义如下:watch事件是一次性触发器,当watch监视的数据发生变化时,通知设置了该watch的client,即watcher. 需要注意三点: 1.一次性触发器 c ...
- Spring Boot(一)
1.注解 @EnableAutoConfiguration 官方文档:The @EnableAutoConfiguration annotation is often placed on your ...
- Spring学习--通过注解配置 Bean (一)
在 classpath 中扫描组件: 组件扫描(component scanning): Spring 能够从 classpath 下自动扫描 , 侦测和实例化具有特定注解的组件. 特定组件包括: @ ...
- hdu1527取石子游戏---(威佐夫博弈)
感谢 http://www.cnblogs.com/yuyixingkong/p/3362476.html 取石子游戏 Time Limit: 2000/1000 MS (Java/Others) ...
- saltstack入门至放弃之salt安装部署
学习了一段时间的saltstack,是时候记录下了.友提:学习环境是两台centos_7.2_x64机器 系统初始化: 两台机器执行以下脚本即可(友提:两台服务器的主机名配置在/etc/hosts中, ...