题目

思路:比赛的时候有想过找循环节,但是,打表打错了。 后来,看着过了挺多人,就急了, 看了一下别人的时间 耗时都挺长的,就以为不是找规律,

没想到真是找规律,不过,这个题的数据可能挺大的。

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[][] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int a[]; int main()
{
int t, i, n;
int sum, x;
sum = ;
for(n = ; n <= ; n++)
{
x = ;
for(i = ; i <= n; i++)
{
x = x*n;
x = x%;
}
sum += x;
sum = sum%;
a[n] = sum;
}
while(cin>>t)
{
while(t--)
{
cin>>n;
x = n%;
if(x==)
x = ;
cout<<s[a[x]]<<endl;
}
}
return ;
}

打表代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
int a[maxn], b[maxn], f[maxn]; int main()
{
int t, i, j, n;
int sum, x, cnt, ad;
while(cin>>t)
{
while(t--)
{
//cin>>n;
sum = ;
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(f, , sizeof(f));
for(n = ; n <= ; n++)
{
x = ;
for(i = ; i <= n; i++)
{
x = x*n;
x = x%; //因为数会非常大,所以利用公式,取余
}
sum += x;
sum = sum%; //因为数会非常大,所以利用公式,取余
a[n] = sum; //把所有结果存入a数组
}
cnt = ;
for(i = ; i <= ; i++)
{
if(a[i]==)
{
b[cnt++] = i; //把结果为1的序号 存入b
f[i] = ;
}
/*cout<<a[i];
if(i%294==0)
cout<<endl<<endl;*/
}
for(i = ; i < cnt; i++)
{
ad = b[i]-; //每一个 的间隔
for(j = ; j <= ; j++) //如果照这个间隔向后推 几次,还是符合间隔的话,就找到了循环节
{
if(f[b[i]+ad*j] != )
break;
}
if(j==)
{
cout<<b[i]<<endl;
break;
}
}
}
}
return ;
}

zoj 3785 What day is that day? (打表找规律)的更多相关文章

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

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  2. 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律

    转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...

  3. ZOJ 3622 Magic Number 打表找规律

    A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  4. zoj 3629 Treasure Hunt IV 打表找规律

    H - Treasure Hunt IV Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

  5. ZOJ 3785 What day is that day?(今天是星期几?)

    Description 题目描述 It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? 今天是星期六,11 + ...

  6. zoj 3785 What day is that day?

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5272 打表找规律. #include <cstdio> #incl ...

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

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

  9. ZOJ问题(2010浙江大学研究生复试上机题目[找规律] hdoj 3788)

    ZOJ问题 pid=3788">点击打开链接 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. c#之反射总结

     1.了解什么事程序集 2.加载程序集 首先要加载需要加载的程序集,然后找到指定的类型,进而往下进行动态加载. 要加载的程序集中的内容: public class Class1:Person { pr ...

  2. Ubuntu下安装配置zsh和oh my zsh

    zsh优势:自动补全功能强大和很高的可配置性 1.查看当前系统装了哪些shell    cat /etc/shells 2.当前正在运行的是哪个版本的shell    echo $SHELL 3.安装 ...

  3. Sandcastle:生成.NET API文档的工具 (帮忙文档)

    (1)准备软件 首先需要我们准备如下软件: SandCastle, 下载地址: http://sandcastle.codeplex.com/releases/view/47665 (2)准备项目文件 ...

  4. PE文件结构详解(一)基本概念

    PE(Portable Execute) 文件是Windows下可执行文件的总称,常见的有DLL,EXE,OCX,SYS等,事实上,一个文件是否是PE文件与其扩展名无关,PE文件可以是任 何扩展名.那 ...

  5. 对于WIFI版ipad(无GPS芯片)定位功能的释疑

    把玩ipad(WIFI版ipad,无GPS芯片)很久时间了,曾今有很多人(包括我)也用过它的定位功能,发现它确实很准确,通常的误差在40米以内,所以很多人都怀疑这个版本的ipad是不是真的内置了GPS ...

  6. c# 与 Unity3d 中的序列化

    圣典中对于Unity3D的序列化介绍很容易和C#的序列化介绍搞混,做个笔记,方便以后查找. 很多资料算是拾人牙慧. 一.Serializable 序列化 Inherits from Attribute ...

  7. python正则表达式——re模块

    http://blog.csdn.net/zm2714/article/details/8016323 re模块 开始使用re Python通过re模块提供对正则表达式的支持.使用re的一般步骤是先将 ...

  8. Oracle composite index column ordering

    Question:  I have a SQL with multiple columns in my where clause.  I know that Oracle can only choos ...

  9. UVA 10246 Asterix and Obelix

    题意:每个城市举办庆祝有一定的花费,A在路径上会选择庆祝花费最大的城市 让你求,A回家所花的路费和庆祝费最少,也就是说并不是最短路径就是结果, 还有可能就是路费比最短路径的多,但是庆祝费就比它的少,总 ...

  10. 拼写sql语句随笔

    DECLARE @str NVARCHAR(1000)='SELECT * FROM dbo.V_MicroUserInfo ',@where VARCHAR(1000)=' where 1=1' D ...