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 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.


Author: ZHOU, Yuchen

Source: The 11th Zhejiang Provincial Collegiate Programming Contest

暴力打表找循环节,,发现是294.。

然后直接mod294输出。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int num[1000];
char day[10][10] = {"Saturday","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int pow(int x)
{
    int ans=1;
    for(int i=1; i<=x; i++)
        ans=(ans*x)%7;
    return ans;
}
int main()
{

    for(int i=1; i<=300; i++)
        num[i]=(pow(i)+num[i-1])%7;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        printf("%s\n",day[num[n%294]]);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-30 11:45:36

ZOJ 3785的相关文章

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?

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",

【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