HDU 1210

感觉就是乱搞找规律

自己写几组数据

本来开始是想着把 n 个数字每次回到原来位置各需要多少次,然后取它们的最小公倍数就好了

但是数据写着写着发现每一个数回到原来位置次数都是一样的,那么就简单了,直接第一个数

为例,不断跟踪位置,计算它走过的次数

 1 #include <cstdio>
 2
 3 int main()
 4 {
 5     int n;
 6     while(scanf("%d" , &n)!=EOF)
 7     {
 8         int k = 2 , ans = 1;
 9         while(k != 1){
10             if( k <= n ) k <<= 1;
11             else k = (k - n)*2-1;
12             ans++;
13         }
14         printf("%d\n" , ans);
15     }
16     return 0;
17 }
时间: 2024-08-04 08:55:13

HDU 1210的相关文章

hdu 1210 Eddy&#39;s 洗牌问题

Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如果他有2N张牌,编号为1,2,3..n,n+1,..2n.这也是最初的牌的顺序.通过一次洗牌可以把牌的序列变为n+1,1,n+2,2,n+3,3,n+4,4..2n,n.那么可以证明,对于任意自然数N,都可以在经过M次洗牌后第一次重新得到初始的顺序.编程对于小于100000的自然数N,求出M的值. Input 每行一个整数N Output 输出与之对应的M Sa

hdu 1210 求置换循环节

这个题的置换恰好是有规律的,所以也不用把置换给存下来,然后只要求出置换的循环节就可以了. 1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 using namespace std; 6 7 const int N = 200001; 8 bool visit[N]; 9 10 int gcd( int x, int y ) 11 {

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

(hdu step 1.3.5)Fighting for HDU(排序)

题目: Fighting for HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2412 Accepted Submission(s): 1210   Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况:在最初的两年里,HDU发

hdoj 1210 Eddy&#39;s 洗牌问题 【模拟】

题意:中文题,不翻译.. 策略:观察可知,第i张牌 如果小于等于n 那么他的序号就会变为i*2, 如果大于n 那么就会变成(i-n)*2-1  故 只需要模拟下就好了 AC by SWS 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1210 代码: #include<stdio.h> int main() { int n, cur, pre; while(scanf("%d", &n) == 1){ int ans

HDU 1695(GCD)

GCD Time Limit: 3000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common

hdu 1210_(逻辑训练)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1210 1 #include<stdio.h> 2 int main() 3 { 4 int n,t,sum; 5 int pos;//记录1的位置 6 while(scanf("%d",&n)!=EOF) 7 { 8 pos=1;//一开始1在第一个位置 9 t=2*n+1; 10 sum=0; 11 while(1) 12 { 13 pos=pos*2%t;//1的下