Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
Problem Statement
We have many oranges. It is known that every orange weighs between AA and BB grams, inclusive. (An orange can have a non-integer weight.)
We chose some of those oranges, and their total weight was exactly WW kilograms.
Find the minimum and maximum possible numbers of oranges chosen. If no set of oranges can weigh exactly WW kilograms in total, report that fact.
Constraints
- 1≤A≤B≤10001≤A≤B≤1000
- 1≤W≤10001≤W≤1000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
AA BB WW
Output
Print the minimum and maximum possible numbers of oranges chosen, in this order, with space in between. If there is no number of oranges that can have the specified total weight, print UNSATISFIABLE
instead.
Sample Input 1 Copy
Copy
100 200 2
Sample Output 1 Copy
Copy
10 20
Here, one range weighs between 100100 and 200200 grams (inclusive).
- If we choose 1010 200200-gram oranges, their total weight will be exactly 22 kilograms.
- If we choose 2020 100100-gram oranges, their total weight will be exactly 22 kilograms.
With less than 1010 oranges or more than 2020 oranges, the total weight will never be exactly 22 kilograms, so the minimum and maximum possible numbers of oranges chosen are 1010 and 2020, respectively.
Sample Input 2 Copy
Copy
120 150 2
Sample Output 2 Copy
Copy
14 16
Here, one range weighs between 120120 and 150150 grams (inclusive).
- If we choose 1010 140140-gram oranges and 44 150150-gram oranges, for example, their total weight will be exactly 22 kilograms.
- If we choose 88 120120-gram oranges and 88 130130-gram oranges, for example, their total weight will be exactly 22 kilograms.
With less than 1414 oranges or more than 1616 oranges, the total weight will never be exactly 22 kilograms, so the minimum and maximum possible numbers of oranges chosen are 1414 and 1616, respectively.
Sample Input 3 Copy
Copy
300 333 1
Sample Output 3 Copy
Copy
UNSATISFIABLE
Here, one range weighs between 300300 and 333333 grams (inclusive).
No set of oranges of this kind can weigh exactly 11 kilograms in total.
官方解答
如果AN≤1000W≤BN,这个问题的答案是肯定的 ,否则不行(想象一下,首先选择重量不变的橘子,然后一点一点地用更重的橘子交换)
code
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 100003
#define mod 100000
#define pb push_back
#define x first
#define y second
#define ull unsigned long long
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int a , b ,w;
cin >> a >> b >> w;
int mx = 0,mn = INF;
for(int i = 1;i <= 1000000;i++)
{
if(a * i <= w * 1000 && b * i >= w * 1000)
{
mn = min(mn,i);
mx = max(mx,i);
}
}
if(mx == 0 || mn == INF)
{
cout << "UNSATISFIABLE" << endl;
}
else
cout << mn << " " << mx << endl;
return 0;
}