POJ 2115 C Looooops(Exgcd)】的更多相关文章

POJ 2115:http://poj.org/problem?id=2115 思路 设循环T次 则要满足A≡(B+CT)(mod 2k) 可得 A=B+CT+m*2k 移项得C*T+2k*m=B-A (因为要满足B大于A)即是Exgcd的标准式子了 代码 #include<iostream> #include<cstdio> using namespace std; #define ll long long ll A,B,C,T,k; int gcd(ll a,ll b) { i…
[题目链接] http://poj.org/problem?id=2115 [题目大意] 求for (variable = A; variable != B; variable += C)的循环次数, 其中变量为k比特无符号整数. [题解] 题目等价于求解Cx=(B–A)(mod 2^k),利用扩展欧几里得算法可以求解该问题 [代码] #include <algorithm> #include <cstring> #include <cstdio> using name…
d.对于这个循环, for (variable = A; variable != B; variable += C) statement; 给出A,B,C,求在k位存储系统下的循环次数. 例如k=4时,变量variable则只在0~15之间循环变化. s.扩展欧几里德求解模线性方程(线性同余方程). 设循环次数为x, 1.(A+C*x)mod 2^k=B. --> C*x=B-A(mod 2^k). (怎么变来的?) 2.C*x=B-A(mod 2^k). --> C*x+(2^k)*y=B-…
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 starts by setting variable to value A and <= x < 2k) modulo 2k. Input The input consists…
http://poj.org/problem?id=2115 题意: 给你一个变量,变量初始值a,终止值b,每循环一遍加c,问一共循环几遍终止,结果mod2^k.如果无法终止则输出FOREVER. 思路: 根据题意原题可化成c * x = b - a mod (2 ^ k),然后解这个模线性方程. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #includ…
链接:传送门 题意:题目中给出一个循环 for (variable = A; variable != B; variable += C) ,这个东东还需要 mod 2^k 问至少多次能退出,如果进入死循环输出输出"FOREVER" 思路:简单拓欧嘛,简单分析一下 A + C * x = B + 2^k * y,如果方程有解,那么最小整数解就是最少次数,否则就是死循环,写了一下快速幂,不清楚普通求 2^k 也并不会T,还是快一点好 /***************************…
嗯... 题目链接:http://poj.org/problem?id=2142 AC代码: #include<cstdio> #include<iostream> using namespace std; inline int _abs(int x){ ) return -x; return x; } inline void exgcd(int a, int b, int &g, int &x, int &y){ ; y = ;} else { exgcd…
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her sa…
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He the…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…