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: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...
随机推荐
- 洛谷 P2827 蚯蚓 解题报告
P2827 蚯蚓 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 ...
- Ajax缓存问题怎么解决?
项目有时要用一些Ajax的效果,因为比较简单,也就没有去用什么Ajax.net之类的东西,手写代码也就实现了.第二天,有人向我报告错误:说是只有第一次读取的值正常,后面的值都不正常:我调试了一下 ,确 ...
- 浅析JavaScript的垃圾回收机制
JavaScript语言是一门优秀的脚本语言.其中包含脚本语言的灵活性外还拥有许多高级语言的特性.例如充许构建和实例化一个对象,垃圾回收机制(GC:Garbage Collecation).通常我们使 ...
- cookie 是存储于访问者的计算机中的变量
今天把javascript如何用来创建及存储cookie复习了一下,其中的一点体会拿出来和大家讨论,首先看一下基础知识: 什么是cookie cookie 是存储于访问者的计算机中的变量.每当同一台计 ...
- Spring事务管理—aop:pointcut expression 常见切入点表达式及事务说明
Spring事务管理—aop:pointcut expression 常见切入点表达式及事物说明 例: <aop:config> <aop:pointcut expression= ...
- bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和
[Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 526 Solved: 2 ...
- 移动端浏览器touch事件的研究总结
$("body").on("touchstart", function(e) { e.preventDefault(); startX = e. ...
- LOJ tangjz的背包
题目大意 有 \(n\) 个物品, 第 \(i\) 个物品的体积为 \(i\) 令 \(f(x)\) 为 选择 \(m\) 个物品, 体积和为 \(x\) 的方案数 令 \(V = \sum_{i=1 ...
- 基于MapReduce的手机流量统计分析
1,代码 package mr; import java.io.IOException; import org.apache.commons.lang.StringUtils; import org. ...
- html初探
HTML HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏 ...