标签:mon pre sum datasets ati and possible oss har
700 300 200 500 200 300 500 200 500 275 110 330 275 110 385 648 375 4002 3 1 10000 0 0 0Sample Output
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
题意:有题意列方程为
a*x1+d=b*y1;
b*x2+d=a*y2;
求minn(x1+y1,x2+y2);
分别用扩展欧几里得求出x1,y1,x2,y2;然后比较两大小,输出较小的一组;
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<queue> #include<map> #include<set> #include<vector> #include<cstdlib> #include<string> #define eps 0.000000001 typedef long long ll; typedef unsigned long long LL; using namespace std; ll abs1(ll n){ if(n<0)n=-n; return n; } ll gcd(ll a,ll b){ if(b==0)return a; else{ return gcd(b,a%b); } } ll exgcd(ll a,ll b,ll &x,ll &y){ if(b==0){ x=1;y=0;return a; } ll r=exgcd(b,a%b,x,y); int t=y; y=x-(a/b)*y; x=t; return r; } int main(){ ll a,b,c;ll x1,y1,x2,y2; while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF){ if(a==0&&b==0&&c==0)break; ll r1=exgcd(a,b,x1,y1); ll r2=exgcd(b,a,x2,y2); x1=x1*c/r1; x2=x2*c/r2; ll t1=b/r1; x1=(x1%t1+t1)%t1; y1=abs1((a*x1-c)/b); ll t2=a/r2; x2=(x2%t2+t2)%t2; y2=abs1((b*x2-c)/a); if(x1+y1<x2+y2)cout<<x1<<" "<<y1<<endl; else{ cout<<y2<<" "<<x2<<endl; } } }
标签:mon pre sum datasets ati and possible oss har
原文地址:http://www.cnblogs.com/Aa1039510121/p/6409667.html