POJ2115C Looooops】的更多相关文章

本题和poj1061青蛙问题同属一类,都运用到扩展欧几里德算法,可以参考poj1061,解题思路步骤基本都一样.一,题意: 对于for(i=A ; i!=B ;i+=C)循环语句,问在k位存储系统中循环几次才会结束. 比如:当k=4时,存储的数 i 在0-15之间循环.(本题默认为无符号) 若在有限次内结束,则输出循环次数. 否则输出死循环.二,思路: 本题利用扩展欧几里德算法求线性同余方程,设循环次数为 x ,则解方程 (A + C*x) % 2^k = B ;求出最小正整数 x. 1,化简方…
线性同余方程的模板题.和青蛙的约会一样. #include <cstdio> #include <cstring> #define LL long long using namespace std; //A+n*C = B mod 2^k //n*C = B-A mod 2^k LL A,B,C,MOD; int k; LL ExGCD(LL a,LL b,LL &x,LL &y) { LL d,t; ) { x=;y=; return a; } d = ExGCD…
http://poj.org/problem?id=1061 第一遍的写法: #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; long long x,y,m,n,l,j1,j2; long long gcd(long long a,long long b) { ?a:gcd(b,a%b); } void e…
链接: https://vjudge.net/problem/POJ-2115 题意: A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which starts by setting variable to value A and while variable i…
http://poj.org/problem?id=2115 k位储存特点,一旦溢出,那么就到第二个循环开始返回0重新计数.问题实际转化成a+cx=b(mod 2^k)跑多少圈能够重合.因为是k位无符号,所以直接就是2^k次方,0~2^k-1.刚好覆盖模的范围 1 #include<iostream> 2 #include<cstdio> 3 #include<math.h> 4 #include<algorithm> 5 using namespace s…
C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24355   Accepted: 6788 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w…
扩展GCD...一定要(1L<<k),不然k=31是会出错的 ....                        C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15444   Accepted: 3941 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable…
C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23637   Accepted: 6528 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w…
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20128 Accepted: 5405 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which…
C Looooops DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repea…