Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 谁能帮我看看吗 我感觉没有错诶

Posted by ZYFniubi at 2018-08-05 17:43:42 on Problem 2142
```#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: