zoj 3785 What day is that day? (打表找规律)
思路:比赛的时候有想过找循环节,但是,打表打错了。 后来,看着过了挺多人,就急了, 看了一下别人的时间 耗时都挺长的,就以为不是找规律,
没想到真是找规律,不过,这个题的数据可能挺大的。
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? (打表找规律)的更多相关文章
- 【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 ...
- ZOJ 3622 Magic Number 打表找规律
A - Magic Number Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
- zoj 3629 Treasure Hunt IV 打表找规律
H - Treasure Hunt IV Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- ZOJ 3785 What day is that day?(今天是星期几?)
Description 题目描述 It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? 今天是星期六,11 + ...
- 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问题(2010浙江大学研究生复试上机题目[找规律] hdoj 3788)
ZOJ问题 pid=3788">点击打开链接 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- SSH与EJB 比较
SSH完全的开源产品,如果用SSH就必然会用到大量的开源的东东,从数据库到逻辑到控制到前端,开源产品大拼装, 其中SSH中的三大核心,Struts相当于JSF,spring相当于EJB,hiberna ...
- 好项目烂架构的问题,四年coder的吐槽
四年多码农,毕业后在一家小私企做前端:(初始asp.net,对oo有了比较深切的理解:处于对某空间的效仿,对前端技术架构理解的比较透彻): 在这家公司混了4个月之后跳出来想自己单干: 自己接了个小项目 ...
- 2729:[HNOI2012]排队 - BZOJ
题目描述 Description某中学有n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人 ...
- Ioc 比较
public interface IC { } public class A { IC ic_; public A(IC ic) { ic_ = ic; } } public class B : IC ...
- Guava文档翻译之 Guava简介
用户指南 User Guide Guava项目包括了一些Google的核心库,是我们在基于Java的项目中所依赖的,这些库包括:集合,缓存,对基本类型的支持,并发库,通用的注解,字符串处理,I/O,等 ...
- Ignore files which are already versioned
If you accidentally added some files which should have been ignored, how do you get them out of vers ...
- DC-DC升压(BOOST)电路原理
BOOST升压电路中: 电感的作用:是将电能和磁场能相互转换的能量转换器件,当MOS开关管闭合后,电感将电能转换为磁场能储存起来,当MOS断开后电感将储存的磁场能转换为电场能,且这个能量在和 ...
- POJ 3104
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7959 Accepted: 2014 Descriptio ...
- iframe标签用法详解(属性、透明、自适应高度)(总结)
<iframe src="http://www.jb51.net" width="200" height="500"> 脚本之家 ...
- Java Excel
http://www.cnblogs.com/mingforyou/archive/2013/08/26/3282922.html