您的位置:首页 > 其它

URAL 2035 Another Dress Rehearsal 水题、易错

2016-07-30 23:10 344 查看
L - Another Dress Rehearsal
Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice URAL
2035

Description

If you have a long history of participating in programming contests, you should know that the dress rehearsal is the most important part
of a contest. There are permanent participants who attend contests not because of results or promotional gifts from sponsors but
specially to solve a new quiz prepared by Alexander Ipatov.

At Ural programming contests, dress rehearsals are made into a cult, and their problems are often prepared more thoroughly than the problems of main contests. For example, have you ever seen rejudging at a dress rehearsals? Now
you understand it.

But however difficult problems the organizers prepare for a dress rehearsal, there is always the good old A + B. Do you think it is
simply copied from one contest to another? Of course not! Any self-respecting organizing committee considers it its duty to prepare
its ownA + B problem with negative numbers and int64.

A contest is approaching, and Kirill has prepared a superdifficult set of tests and answers to them. Unfortunately, he forgot to backup
the tests, and, after an update of the Hardsoft Doors operating system, all the test were lost. It will take some time before Kirill invents theAwesome
Backup System, but that’s a different story.

Now Kirill has to recover the lost tests as soon as possible. He has answers to the tests, and he remembers that the summands A and Bwere integers such that 0 ≤ A ≤ X and 0 ≤ B ≤ Y.
Help Kirill recover the tests!

Input

The only input line contains integers X, Y, and C separated with a space (0 ≤ X, Y, C ≤ 10 9).

Output

Find integers A and B such that 0 ≤ A ≤ X, 0 ≤ B ≤ Y, and A + B = C.

If Kirill is wrong and there are no such integers, output “Impossible” (without quotation marks). Otherwise, output the integers A and Bseparated with a space. If there are several pairs satisfying the conditions,
output any of them.

Sample Input

inputoutput
2 7 5

2 3

9 15 100

Impossible

Source

UESTC 2016 Summer Training #17 Div.2

URAL 2035

My Solution

虽然是水题但也WA了两发, 尴尬,

第一次WA, 是对于 x > c && y > c的情况没有处理好

第二次WA, 是由于 0 ≤ A ≤ X,
0 ≤ B ≤ Y

没有注意, 因为 A最大不能超过X, B 最大不能超过Y,

这个相对的就是如果 a = min(x, y) < c, 但是 max(x, y) > c, 这个时候可以 如果 y 小 则 b = y; a = c - b; 或者其实可以直接令大的为c, 然后小的为0 ☺☺

#include <iostream>
#include <cstdio>

using namespace std;
typedef long long LL;
const int maxn = 1e6 + 8;

int main()
{
#ifdef LOCAL
freopen("a.txt", "r", stdin);
//freopen("b.txt", "w", stdout);
int T = 5;
while(T--){
#endif // LOCAL
//WA 5 6 0
int x, y, c, a, b;
scanf("%d%d%d", &x, &y, &c);
if(x + y < c) printf("Impossible");
else{
a = min(x, y);
if(c >= a){
if(x > y){
b = y;
a = c - b;
}
else{
a = x;
b = c - a;
}
printf("%d %d", a, b);
}
else{
if(x > y){
b = 0;
a = c;
}
else{
a = 0;
b = c;
}
printf("%d %d", a, b);
}

}
#ifdef LOCAL
printf("\n");
}
#endif // LOCAL
return 0;
}


Thank you!

------from ProLights
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: