题目

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

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

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. Inject js code to exchange 2013

    1. save the following code to C:\Program Files\Microsoft\Exchange Server\V15\FrontEnd\HttpProxy\owa ...

  2. 【狼窝乀野狼】Serializer妙手回春

    在我们很多程序中,需要将数据保存到本地,以便于下次打开还能看到原始数据.例如我们Xmind思维导图,例如我们的Power Designer等等,都是有保存一个隶属于自己的工程文件,那么今天我要说的就是 ...

  3. [转载]关于安装Android Studio的一些问题的解决方法

    最近在研究Android编程,在Android Studio安装和使用时遇到了麻烦,从园子里找到了<关于安装Android Studio的一些问题的解决方法>的,很多问题找到了解决办法. ...

  4. OpenCV+QT开发环境(一):Windows环境

    最近在学习openCV的开发.在搭建开发环境的时候,着实废了不少功夫,找了大量的文章资料.其实主要的开发还是在linux系统上的openCV,但是为了方便,我还是在windows上也搭建了开发环境,这 ...

  5. 在云服务器搭建WordPress博客(四)WordPress的基本设置

    前面说了 如何安装WordPress,接下来我们需要快速熟悉WordPress,以及进行一些必要的基本设置. 开始设置之前,建议大家先点击一篇左边菜单栏的每一个选项,看看到底是做什么用的.下面开始说一 ...

  6. c++ std::string 用法

    std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...

  7. vs2010 mvc3创建的razor引擎模板页,子页面引用后出现当前上下文中不存在名称“ViewBag”

    View文件夹下缺少Web.config

  8. ASP文件操作(FSO)详解

    实例一:写入文件 语法 object.CreateTextFile([要建立的文件],[如存在,是否替代]) <% Set fs =Server.CreateObject("Scrip ...

  9. Unity3d 接入 移动MM支付SDK(2.3) 全攻略

    原地址:http://blog.csdn.net/dingxiaowei2013/article/details/26842177 先将例程运行起来 下载例程(csdn积分不够上传不了,只能用百度网盘 ...

  10. Browser detect

    A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give s ...