LightOj 1001 - Opposite Task (数值和的拆分)
2016-09-08 11:39
531 查看
http://www.lightoj.com/volume_showproblem.php?problem=1001
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.
Each case starts with a line containing an integer n (0 ≤ n ≤ 20) denoting the total number of problems.
1.如果是上一步已经给定的,这次的 a 需要自加 1,;
2.不存在大于 10 的加数;
3.不存在负数的加数。
直接看注释吧。
#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;
}
1001 - Opposite Task
![]() ![]() | PDF (English) | Statistics | Forum |
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
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;
}
相关文章推荐
- LightOJ-1001-Opposite Task
- LightOJ - 1001 Opposite Task
- 基础数论 1001 LightOJ 1370
- HDU 5104 Primes Problem(拆分素数和问题)【BestCoder Round #18 1001】
- 欧洲数值天气预报文件拆分方法
- lightoj1001【简单题】
- lightoj 1214 - Large Division 【判大数整除 拆分字符串 同余】
- POJ 1001 计算小数n次幂准确数值
- [LightOJ1028]Trailing Zeroes (I)(拆分因子)
- Uva 11235 频繁出现的数值(RMQ-Sparse Table 算法)(训练指南)
- 12.对字符串中的数值进行操作
- 最简单的基于FFMPEG+SDL的音频播放器:拆分-解码器和播放器
- tyvj 1087 拆分 - 递推
- java读取Excel数值型会把它转换成科学计数法
- javascript实现一个数值加法函数
- Lightoj 1068 数位dp
- LightOJ1079---Just another Robbery
- 对象函数asp获取和js中date对象getTime一样的数值
- C++常量(C++数值常量、字符串常量、符号常量)
- lightoj 1198(贪心)