http://www.lightoj.com/volume_showproblem.php?problem=1001
1001 - Opposite Task
| Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
This problem gives you a flavor the concept of special judge. That means the judge is smart enough to verify your code even though it may print different results. In this problem you are asked to find the opposite task of the previous problem.
To be specific, I have two computers where I stored my problems. Now I know the total number of problems is n. And there are no duplicate problems and there can be at most 10 problems in each computer. You have to find the number of problems in each of the computers.
Since there can be multiple solutions. Any valid solution will do.
Input
Input starts with an integer T (≤ 25), denoting the number of test cases.
Each case starts with a line containing an integer n (0 ≤ n ≤ 20) denoting the total number of problems.
Output
For each case, print the number of problems stored in each computer in a single line. A single space should separate the non-negative integers.
Sample Input | Output for Sample Input |
| 3 10 7 7 | 0 10 0 7 1 6 |
题意:
真是坑人的思路,给一个数字,让我们拆分两个数相加的形式,要求:1.如果是上一步已经给定的,这次的 a 需要自加 1,;
2.不存在大于 10 的加数;
3.不存在负数的加数。
思路:
题目简单,但是错了很多次,这就是LightOJ的风格!直接看注释吧。
参考Code:
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define AC main()
using namespace std;
const int MYDD = 1103;
int AC {
int tt, a, b, Last = -1;
scanf("%d", &tt);
while(tt--) {
int n;
scanf("%d", &n);
if(n == 0) {
puts("0 0");
continue;
}
if(n == Last) a++;/*和上一次键入数字相等*/
else a = 0;
b = n - a;
if(b > 10) {/*处理加数 > 10的情况*/
b = 10;
a = n - b;
}
if(a < 0 || b < 0) {/*处理负数的情况*/
a = 0;
b = n - a;
if(b > 10) {/*处理加数 > 10的情况*/
b = 10;
a = n - b;
}
}
printf("%d %d\n", a, b);
if(a > 10) a = 0;
Last = n;
}
return 0;
}


2239

被折叠的 条评论
为什么被折叠?



