ZOJ 3785 What day is that day?(今天是星期几?)
|
Description |
题目描述 |
|
It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? |
今天是星期六,11 + 22 + 33 + ... + NN 天后是星期几? |
|
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). |
多组测试样例。 输入的首行是一个整数T表示测试样例的数量。每个测试样例包含: 只有一行,且每行只有一个整数N (1 <= N <= 1000000000)。 |
|
Output |
输出 |
|
For each test case, output one string indicating the day of week. |
每个测试样例输出一个字符串表示星期几。 |
|
Sample Input - 输入样例 |
Sample Output - 输出样例 |
|
2 1 2 |
Sunday Thursday |
|
Hint |
提示 |
|
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday. |
一周中包含Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday。 |
【题解】
想算出最后是星期几,只要把天数模7就能得到增长了的星期数,从而换算出具体星期。
因此我们需要计算的式子可表示为:
(11+ 22+ 33+...+ NN)%7
11%7+ 22%7+ 33%7+...+ NN%7
然后对于大等于7的数,aN%7可以得到:
7N%7 = (7%7)N%7 = 0N,8N%7 = (8%7)N%7 = 1N,…………以此类推
后继的元素全部遵循这个规律,因此所求a的值为[ 0, 6]。
对于aN%7,a属于[ 0, 6]:
|
元素\次方%7 |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
|
0 |
0%7已经为0,其结果全部为0 |
||||||
|
1 |
1 |
1……出现循环 |
|||||
|
2 |
1 |
2 |
4 |
1……出现循环 |
|||
|
3 |
1 |
3 |
2 |
6 |
4 |
5 |
1……出现循环 |
|
4 |
1 |
4 |
2 |
1……出现循环 |
|||
|
5 |
1 |
5 |
4 |
6 |
2 |
3 |
1……出现循环 |
|
6 |
1 |
6 |
1……出现循环 |
||||
所求式子可展开为:
|
第一层 |
11 |
22 |
33 |
44 |
55 |
66 |
07 |
|
第二层 |
18 |
29 |
310 |
411 |
512 |
613 |
014 |
|
第三层 |
115 |
216 |
317 |
418 |
519 |
620 |
021 |
|
第四层 |
122 |
223 |
324 |
425 |
526 |
627 |
028 |
|
第五层 |
129 |
230 |
331 |
432 |
533 |
634 |
035 |
|
第六层 |
136 |
237 |
338 |
439 |
540 |
641 |
042 |
|
第七层 |
…………………………………………………… |
||||||
然后把每层加起来再%7,可以得到长度为6*7 = 42的循环节。
然后根据每层的循环节套上每个元素的循环节,得到最终循环节,长度为42*7 = 294
附:原本想比较科学地证明最终循环节的长度是294,最后发现坑越挖越大,然后以现在的渣水平填不上,就弃了……
【代码 C++】
#include<cstdio>
int day[] = {
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , ,
};
char opt[][] = {
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
};
int main(){
int t, a;
scanf("%d", &t);
while (t--){
scanf("%d", &a);
puts(opt[day[a % ]]);
}
return ;
}
ZOJ 3785
ZOJ 3785 What day is that day?(今天是星期几?)的更多相关文章
- zoj 3785 What day is that day? (打表找规律)
题目 思路:比赛的时候有想过找循环节,但是,打表打错了. 后来,看着过了挺多人,就急了, 看了一下别人的时间 耗时都挺长的,就以为不是找规律, 没想到真是找规律,不过,这个题的数据可能挺大的. AC代 ...
- zoj 3785 What day is that day?
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272 打表找规律. #include <cstdio> #incl ...
- ZOJ 3785 What day is that day?(数论:费马小定理)
What day is that day? Time Limit: 2 Seconds Memory Limit: 65536 KB It's Saturday today, what da ...
- ZOJ 3785:What day is that day?(数论)
What day is that day? Time Limit: 2 Seconds Memory Limit: 65536 KB It's Saturday today, what day is ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- 2014 Super Training #4 G What day is that day? --两种方法
原题: ZOJ 3785 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3785 题意:当天是星期六,问经过1^1+2^2+ ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- ActiveMQ实现负载均衡+高可用部署方案(转)
本文转自:http://www.open-open.com/lib/view/open1400126457817.html%20 一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最 ...
- Java简单数据类型转换
1. Integer<---String (1) Integer x = new Integer(Integer.parseInt(String)); 2. Integer<--- ...
- Linux下通过crontab及expect实现自动化处理 --亲测可用
#!/usr/bin/expect -fspawn /home/scripts/bckup.shexpect "Enter password: " send "WWQQ ...
- MyISAM表杂记实验
一.本文说明 由于刚学mysql所以动手做了一些实验. 二.实验内容 1.验证MyISAM有AUOT_INCREMENT coloumn功能 ----在这里是对现有表t,增加一个主键----mysql ...
- POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K T ...
- 去掉DataTable中重复的行
//DataView dv = dt3.DefaultView; //dt3默认的虚拟视图 //dv.Sort = "wmid asc"; //排序 ///dv.ToTab ...
- Bag Problem
Bag Problem Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/131072 K (Java/Others) Total ...
- ZENG msgbox仿qq提示
ZENG.msgbox.show("设置成功!", 4, 2000); ZENG.msgbox.show("服务器繁忙,请稍后再试.", 1, 2000); Z ...
- acdream 1093 女神的正多面体
http://acdream.info/problem?pid=1093 女神的正多面体 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 12 ...
- CSS——清除浮动
<div id="main" class="clear"> <div id="left"> </div> ...