ZOJ 3785 What day is that day?
2015-08-23 18:25
323 查看
J - What day is that day?
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
SubmitStatusPracticeZOJ
3785
Description
It's Saturday today, what day is it after 11 + 22 + 33 + ... +
NN days?
Input
There are multiple test cases. The first line of input contains an integer
T indicating the number of test cases. For each test case:
There is only one line containing one integer N (1 <= N <= 1000000000).
Output
For each test case, output one string indicating the day of week.
Sample Input
Sample Output
做法:先暴力地把结果写入文件,在文件里面观察,然后得到规律,发现循环周期为294,之后就好办了,打一个1-294的表,之后每次去模查表就行了。
当然做法有很多,貌似还有等比数列求和的做法。把每一项的底数%7,7个排一行,会发现,上下对应的数刚好能成为等比数列,然后用等比数列的求和公式做。
个人认为我的方法算是比较快了。20ms
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
SubmitStatusPracticeZOJ
3785
Description
It's Saturday today, what day is it after 11 + 22 + 33 + ... +
NN days?
Input
There are multiple test cases. The first line of input contains an integer
T indicating the number of test cases. For each test case:
There is only one line containing one integer N (1 <= N <= 1000000000).
Output
For each test case, output one string indicating the day of week.
Sample Input
2 1 2
Sample Output
Sunday Thursday
Hint
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.做法:先暴力地把结果写入文件,在文件里面观察,然后得到规律,发现循环周期为294,之后就好办了,打一个1-294的表,之后每次去模查表就行了。
当然做法有很多,貌似还有等比数列求和的做法。把每一项的底数%7,7个排一行,会发现,上下对应的数刚好能成为等比数列,然后用等比数列的求和公式做。
个人认为我的方法算是比较快了。20ms
#include <stdio.h> #define MOD 7 #define N 300 int table ; long long PowMod(long long a, long long n) { long long ret = 1; while(n) { if(n & 1) ret = ret * a % MOD; a = a * a % MOD; n >>= 1; } return ret%MOD; } void gettable() { for(int i=1;i<=294;i++) { long long sum=0; for(int j=1;j<=i;j++) sum+=PowMod(j,j)%MOD; table[i]=sum%MOD; } } int main() { gettable(); int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int cnt=table[n%294]; switch(cnt) { case 0: printf("Saturday\n"); break; case 1: printf("Sunday\n"); break; case 2: printf("Monday\n"); break; case 3: printf("Tuesday\n"); break; case 4: printf("Wednesday\n"); break; case 5: printf("Thursday\n"); break; case 6: printf("Friday\n"); break; } } return 0; }
相关文章推荐
- PAT 1089. Insert or Merge (25)
- java中的各种Queue
- make uImage 与make iImage的区别
- Java实现KMP算法
- java内存溢出示例(堆内存、栈内存)
- 《how tomcat work》 搬运工 Chapter 6:Lifecycle & Chapter 7:Logger &Chapter 8: Loader
- 洛谷1387 最大正方形 解题报告
- HashMap和TreeMap区别详解以及底层实现
- HashMap
- Nginx开发从入门到精通四
- ZOJ 3782 Ternary Calculation
- 大批量数据插入比较
- [Leetcode] Roman to Integer
- HDU 2242 考研路茫茫——空调教室
- SQLmap
- 黑马程序员------Java缓存—浅谈Memcached
- python中的urlencode与urldecode
- BA-siemens-点位类型表
- iOS prototype Cells
- 虚拟机搭建Hadoop集群(1) ---nat模式