标签:sample previous limit more cin cal measure ext ini
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 6325 | Accepted: 2787 |
Description
Input
Output
Sample Input
700 300 200 500 200 300 500 200 500 275 110 330 275 110 385 648 375 4002 3 1 10000 0 0 0
Sample Output
1 3 1 1 1 0 0 3 1 1 49 74 3333 1
Source
#include <cstdio> #include <algorithm> int exgcd(int a,int b,int &x,int &y){ if(b==0){ x=1; y=0; return a; } int ans=exgcd(b,a%b,y,x); y-=a/b*x; return ans; } int main() { int a=1,b,c,x,y; bool Gavin; while (a || b || c){ scanf("%d%d%d",&a,&b,&c); if (!a&&!b&&!c) break; //之前没有加这一句,输入最后的000结束时会继续运行一次,致命错误,被0除。 Gavin=0; if(a<b){ swap(a,b);Gavin=1; } int gcd=exgcd(a,b,x,y); a/=gcd;b/=gcd;c/=gcd; x*=c;y*=c; int t=y/a,x1,y1,x2,y2,ansx,ansy; while(y-a*t<0) t--; x1=abs(x+b*t);y1=abs(y-a*t); t++; x2=abs(x+b*t);y2=abs(y-a*t); if ((x1+y1<x2+y2)||(x1+y1==x2+y2)&&(x1*a+y1*b<x2*a+y2*b)) ansx=x1,ansy=y1; else ansx=x2,ansy=y2; if(Gavin) printf("%d %d\n",ansy,ansx); else printf("%d %d\n",ansx,ansy); } return 0; }
标签:sample previous limit more cin cal measure ext ini
原文地址:http://www.cnblogs.com/suishiguang/p/6366250.html