HDU 5832 A water problem(某水题)
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description - 题目描述
Two planets named Haha and Xixi in the universe and they were created with the universe beginning.
There is 73 days in Xixi a year and 137 days in Haha a year.
Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.
宇宙之中有Haha与Xixi两星,鸿蒙时代既存。 Xixi一年73天,Haha一年137天 现在你被告知宇宙大爆炸后已过N天,待你断定这是否是两颗星球一年中的第一天。
CN
Input - 输入
There are several test cases(about 5 huge test cases).
For each test, we have a line with an only integer N(0≤N), the length of N is up to 10000000.
多组测试用例(大约5组特大数据)。 对于每组测试用例,给出一行仅有一个整数N(≤N),N的长度高达10000000。
CN
Output - 输出
For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.
对于第i个测试用例,先输出Case #i: ,再输出回答"YES"或"NO"。
CN
Sample Input - 输入样例
10001
0
333
Sample Output - 输出样例
Case #1: YES
Case #2: YES
Case #3: NO
题解
大数取模
类似输入挂的读取方式,不过直接按照输入挂的做法读取一个字符处理一次IO开销太大,会超时,先保存进数组再处理可以极大地提高速度。
代码 C++
#include <cstdio>
#define mod 10001
char data[];
int main(){
int n, i = , j;
while (gets(data)){
printf("Case #%d: ", ++i);
for (j = n = ; data[j]; ++j) n = (n * + data[j] - '') % mod;
if (n == ) puts("YES");
else puts("NO");
}
return ;
}