HNU2[J题]Modified LCS 扩展GCD
2014-07-22 08:41
295 查看
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12831&courseid=268
解题思路:求出最小的两个为正且相等的下标(利用扩展GCD),然后就可以直接求了。
解题代码:
View Code
解题思路:求出最小的两个为正且相等的下标(利用扩展GCD),然后就可以直接求了。
解题代码:
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <queue> #include <map> #include <stack> #include <list> #include <vector> using namespace std; #define LL __int64 LL x,y,gcd; void exgcd(LL a ,LL b) { if (!b) { x=1; y=1; gcd=a; return; } exgcd(b,a%b); LL t=x; x=y; y=t-a/b*y; return ; } int main() { int T; LL n1,n2,f1,f2,d1,d2; // freopen("in.txt", "r", stdin); // freopen("outt.txt","w",stdout); scanf("%d",&T); while (T--) { cin>>n1>>f1>>d1>>n2>>f2>>d2; LL f=f2-f1; exgcd(d1,-d2); if (f % gcd) { puts("0"); continue; } else { LL r=abs((-d2)/gcd); x=(x*f/gcd % r+r)%r; y=(f-x*d1)/(-d2); LL dx=abs(d1/gcd); LL dy=abs(d2/gcd); LL ans=min((n1-x-1)/dy,(n2-y-1)/dx)+1; //if (ans<0) ans=0; cout<<ans<<endl; } } return 0; }
View Code
相关文章推荐
- [CF338D]GCD Table(扩展中国剩余定理)
- poj 1061 青蛙的约会 数论扩展GCD
- 扩展gcd以及同余方程ax=b(mod M)
- 扩展GCD 中国剩余定理(CRT) 乘法逆元模版
- POJ2947 Widget Factory 高斯消元+扩展GCD解同余方程组
- gcd,扩展欧几里得,中国剩余定理
- poj2115--C Looooops(扩展gcd)
- GCD及其扩展GCD详解
- gcd欧几里德算法/extgcd扩展欧几里德算法以及在解不定方程中的应用
- POJ 1061扩展gcd
- gcd,扩展gcd
- POJ-2115 C Looooops 扩展GCD
- GCD及其扩展GCD详解
- A/B 扩展gcd(或逆元)
- poj 1061 青蛙的约会(扩展gcd)
- 扩展GCD 中国剩余定理(CRT) 乘法逆元模版
- POJ 2115 C Looooops 扩展gcd的应用 及其 gcd exgcd的讲解
- 扩展gcd求解二元不定方程及其证明
- 扩展GCD
- 1061 青蛙的约会 数论 扩展GCD