URAL 2048 Histroy(打表+模拟)
因为年历是400年一个循环节的,所以递推出一年的情况,然后递推处理出一个循环节的情况。对于询问,求一个类似前缀和的东西就好了。
跑出来和比样例小一,把A和B加一以后交后AC...
写得时候注意变量的定义。。。不然WA到哭。。。我是以6代表星期5的,1900年是第一年,所以B,A减去1900之前要加一。
#include<cstdio>
#include<cstring> bool isLeapYear(int y)
{
if(y%){
return !(y&);
}
else {
return !(y%);
}
}
// 1 3 5 7 8 10 12
int days[] = {-,,,,,,,,,,,,};
//6 7 1 2 3 4 5
int cnt1[];//1~2月
int cnt2[];//2月以后
int cnt[]; //
void firstYear()
{
int v = ;
for(int m = ; m <= ; m++) {
cnt1[v]++;
v = (v+days[m])%;
}
for(int m = ; m <= ; m++) {
cnt2[v]++;
v = (v+days[m])%;
}
for(int i = ; i < ; i++) {
cnt[i] = cnt1[i]+cnt2[i];
}
} int cnt400[][];
int cntCur[]; void circle()
{
firstYear();
int mov = ;
int i = ;//
for(int y = ; y < ; y++,i++){//1,1 +mov1 1,2 2->last 1
memset(cntCur,,sizeof(cntCur));
if(isLeapYear(y)) {
for(int i = ; i < ; i++)//2月以前不受影响
cntCur[i] += cnt1[(i-mov+)%];
mov = (mov + )%;//相对上一年
for(int i = ; i < ; i++)
cntCur[i] += cnt2[(i-mov+)%]; }
else {
for(int i = ; i < ; i++)
cntCur[i] += cnt[(i-mov+)%];
}
mov = (mov + )%;//365%7 =1
for(int j = ; j < ; j++){
cnt400[i][j] = cnt400[i-][j];
}
cnt400[i][cntCur[]]++;
}
} int ans[];
//#define local
int main()
{
#ifdef local
freopen("data.txt","w",stdout);
#endif // local
int A,B;
circle();
scanf("%d%d",&A,&B);
B++;A++;
int a = (A--)%;
int na = (A--)/;
int b = (B-)%;
int nb = (B-)/;
for(int i = ; i < ; i++){
ans[i] += (nb-na)*cnt400[][i] + cnt400[b][i] - cnt400[a][i];
}
for(int i = ; i < ; i++)
printf("%d: %d\n",i,ans[i]); return ;
}
URAL 2048 Histroy(打表+模拟)的更多相关文章
- Oracle本地网络分表模拟分区裁剪
来自讨论贴 http://www.itpub.net/thread-1877111-1-1.html 准备数据表 2014-07-20 01:38:10>create table tb_1 as ...
- URAL 2047 Maths 打表 递推
MathsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- 2018.09.25 codeforces1053E. Euler tour(并查集+st表+模拟)
传送门 毒瘤细节题. 首先考虑不合法的情况. 先把相同的值配对,这样就构成了一些区间. 那么如果这些区间有相交的话,就不合法了. 如何判断?DZYO安利了一波st表,我觉得很不错. 接着考虑两个相同的 ...
- 【洛谷】【st表+模拟】P1311 选择客栈
[题目描述:] 丽江河边有n 家很有特色的客栈,客栈按照其位置顺序从 1 到n 编号.每家客栈都按照某一种色调进行装饰(总共 k 种,用整数 0 ~ k-1 表示),且每家客栈都设有一家咖啡店,每家咖 ...
- URAL 1069 Prufer Code(模拟)
Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...
- URAL(timus) 1280 Topological Sorting(模拟)
Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...
- URAL 2048 History 蔡勒公式
HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】
这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...
- oracle 表迁移方法 (一)
在生产系统中,因业务需求,56张表中清空54张表数据,另外两张表数据保留,数据量大约10G左右:1.大部分人想法就是expdp/impdp,的确是这样,哈哈 2.rman 3.以下方法,move 虚拟 ...
随机推荐
- 20个Flutter实例视频教程-第07节: 毛玻璃效果制作
视频地址: https://www.bilibili.com/video/av39709290/?p=7 博客地址: https://jspang.com/post/flutterDemo.html# ...
- 使用Try.NET创建可交互.NET文档
原文地址:Create Interactive .NET Documentation with Try .NET 原文作者:Maria 译文地址:https://www.cnblogs.com/lwq ...
- 正向渲染路径细节 Forward Rendering Path Details
http://www.ceeger.com/Components/RenderTech-ForwardRendering.html This page describes details of For ...
- [HNOI2010] 平面图判定 planar
标签:二分图判定.题解: 首先可以把题目中给你的那个环给画出来,这样就可以发现对于任意一个图来说,如果两条边要相交,就不能让他们相交,那么这两条边就要一条在里面一条在外面,如果把环画成一条链,那么就是 ...
- echarts相关属性设置(2)--折线图和柱状图的结合使用
type:bar和line的组合 option = { { tooltip: { trigger: 'axis', axisPointer: { // type: 'shadow' }, // lab ...
- 黑马tomact学习二 tomcat的启动
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...
- [題解]luogu_P3205/BZOJ_1996 合唱隊
前言:基本上發題解的都是抄的題解所以 來源:題解 题目描述 为了在即将到来的晚会上有更好的演出效果,作为AAA合唱队负责人的小A需要将合唱队的人根据他们的身高排出一个队形.假定合唱队一共N个人,第i个 ...
- Codeforces Round #396 (Div. 2) D
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are ...
- JAVA Debug调试技术
System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常,不过它和另外一个e.printStackTrace()方法不同.后者也是打印出异常,但是它还将显示出更深的调用 ...