35 lines
741 B
C
35 lines
741 B
C
#include <stdio.h>
|
||
|
||
/*
|
||
* 三种鸡单价分别为 R, S, 1/T,其中 R > S
|
||
* 花 M 钱买 N 只
|
||
*/
|
||
void calc(int R, int S, int T, int M, int N)
|
||
{
|
||
int v = 0;
|
||
int r = 1;
|
||
for (; r < N && r * R < M; r++) {
|
||
int m = M - R * r;
|
||
int n = N - r;
|
||
if (m >= n * S || m * T <= n) continue;
|
||
|
||
int a = T * m - n;
|
||
int b = T * (S * n - m);
|
||
int c = S * T - 1;
|
||
if (a < 0 || b < 0 || a % c || b % c) continue;
|
||
|
||
int s = a / c;
|
||
int t = b / c;
|
||
printf("----- %d -----\n", ++v);
|
||
printf("%d + %d + %d = %d\n", r, s, t, N);
|
||
printf("%d * %d + %d * %d + %d / %d = %d\n", r, R, s, S, t, T, M);
|
||
}
|
||
}
|
||
|
||
|
||
int main()
|
||
{
|
||
calc(5, 3, 3, 100, 100);
|
||
return 0;
|
||
}
|