Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁能帮我看看吗 我感觉没有错诶#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; struct acm{ int x,y; }; int a,b,d,x,y; acm node[50001]; bool cmp(acm m,acm n) { if(m.x + m.y != n.x + n.y) return m.x + m.y < n.x + n.y; else return m.x * a + m.y * b < n.x * a + n.y *b; } int main() { while (~scanf("%d%d%d",&a,&b,&d)) { memset(node, 0, sizeof(node)); if(a == 0 && b == 0 && d == 0) break; int MIN = 9999999,t = 0; for(int i = 0 ; i <= 50000 ; i++) { if(MIN != 9999999 && i > MIN)break; if((a * i - d) >= 0 && (a * i - d) % b == 0) { int ans = i + ( (a * i - d) / b ); if(MIN > ans ) { MIN = ans; node[t].x = i; node[t].y = (a * i - d) / b; t++; } } if((a * i + d) >= 0 && (a * i + d) % b == 0) { int ans = i + ( (a * i + d) / b ); if(MIN > ans ) { MIN = ans; node[t].x = i; node[t].y = (a * i + d) / b; t++; } } if((a * i - d) <= 0 && (a * i - d) % ((-1) * b) == 0) { int ans = i + ( (a * i - d) / ((-1) * b) ); if(MIN > ans ) { MIN = ans; node[t].x = i; node[t].y = ( (a * i - d) / ((-1) * b) ); t++; } } } sort(node,node + t,cmp); printf("%d %d\n",node[0].x,node[0].y); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator