zoj 3785 What day is that day?

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272

打表找规律。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define LL long long
 5 using namespace std;
 6 const int mod=7;
 7 char g[][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
 8 int a[300];
 9
10 LL pow_m(LL a,LL n)
11 {
12     LL ret=1;
13     LL temp=a%mod;
14     while(n)
15     {
16         if(n&1) ret=(ret*temp)%mod;
17         temp=temp*temp%mod;
18         n>>=1;
19     }
20     return ret;
21 }
22
23 int deal(int n)
24 {
25     int ans=1;
26     for(int i=1; i<=n; i++)
27     {
28         ans*=n;
29         ans%=mod;
30     }
31     return ans;
32 }
33
34 int main()
35 {
36     int t;
37     scanf("%d",&t);
38     a[0]=0;
39     for(int i=1; i<=294; i++)
40     {
41         a[i]=a[i-1]+deal(i);
42         a[i]%=mod;
43     }
44     while(t--)
45     {
46         int n;
47         scanf("%d",&n);
48         int ans=a[(n%294)];
49         printf("%s\n",g[ans]);
50     }
51     return 0;
52 }

时间: 2024-10-13 22:08:22

zoj 3785 What day is that day?的相关文章

ZOJ 3785 What day is that day? 数论

LINK: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3785 题意:求 \(1^1+2^2+3^3+…+n^n\) 加1模7的值 思路:其实这题是找规律题...说数论是不甘心,这题卡了好久,借助python打表发现 指数每6循环 n值每7循环 6*7=42 但每42个数后它们的排列就会发生改变,共改变7次,所以总循环周期为42*7=294,预处理记录一下就好. /** @Date : 2017-03-23-23.0

ZOJ 3785

What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 o

【ZOJ】3785 What day is that day? ——浅谈KMP应用之ACM竞赛中的暴力打表找规律

首先声明一下,这里的规律指的是循环,即找到最小循环周期.这么一说大家心里肯定有数了吧,“不就是next数组性质的应用嘛”. 先来看一道题 ZOJ 3785 What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple tes

2014浙江省赛

ZOJ 3777 Problem Arrangement 状态压缩DP,种数DP,dp[s][m]代表当前被占位置的集合分数为m的方案数,父母是总数n!,记忆化搜索好写 by fd ZOJ 3785 What day is that day? 等比数列,逆元,快速幂,当然可以暴力找循环节,有mod肯定有循环节,因为x^y%7 等价于(x%7)^y,所以可以分成6个第比数列,如下 1^1,2^2,3^3,4^4,5^5,6^6,0^7 1^8,2^9,3^10,4^11,5^12,6^13,0,^

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+3^3....+n^n天后是星期几? 这题开始以为是这种式子的求和问题,翻了半天没翻到公式.结果没搞出来.后来发现有两种方法. 第一种方法: 找规律 打表可以看出,这些数的结果出现42一循环,所以直接就处理出前42个,后面的就用前面的. 代码: #include <iostream> #inclu

[暑假集训]区域赛套题集

2014-07-03 [浙江第11届省赛]ZOJ 3785 What day is that day?  (打表找循环节) [暑假集训]区域赛套题集

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio