因为年历是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(打表+模拟)的更多相关文章

  1. Oracle本地网络分表模拟分区裁剪

    来自讨论贴 http://www.itpub.net/thread-1877111-1-1.html 准备数据表 2014-07-20 01:38:10>create table tb_1 as ...

  2. URAL 2047 Maths 打表 递推

    MathsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  3. 2018.09.25 codeforces1053E. Euler tour(并查集+st表+模拟)

    传送门 毒瘤细节题. 首先考虑不合法的情况. 先把相同的值配对,这样就构成了一些区间. 那么如果这些区间有相交的话,就不合法了. 如何判断?DZYO安利了一波st表,我觉得很不错. 接着考虑两个相同的 ...

  4. 【洛谷】【st表+模拟】P1311 选择客栈

    [题目描述:] 丽江河边有n 家很有特色的客栈,客栈按照其位置顺序从 1 到n 编号.每家客栈都按照某一种色调进行装饰(总共 k 种,用整数 0 ~ k-1 表示),且每家客栈都设有一家咖啡店,每家咖 ...

  5. URAL 1069 Prufer Code(模拟)

    Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...

  6. URAL(timus) 1280 Topological Sorting(模拟)

    Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...

  7. URAL 2048 History 蔡勒公式

     HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  8. 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】

    这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...

  9. oracle 表迁移方法 (一)

    在生产系统中,因业务需求,56张表中清空54张表数据,另外两张表数据保留,数据量大约10G左右:1.大部分人想法就是expdp/impdp,的确是这样,哈哈 2.rman 3.以下方法,move 虚拟 ...

随机推荐

  1. Flutter从入门到进阶实战携程网App_汇总贴

    视频地址:https://coding.imooc.com/class/321.html?mc_marking=60e5294c605a87b2af7257d06f70505e&mc_chan ...

  2. ASP.NET页面执行顺序

    原文地址:http://blog.csdn.net/a497785609/article/details/4510335 1.对象初始化(OnInit方法) 页面中的控件(包括页面本身)都是在它们最初 ...

  3. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  4. iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架

    cocoapods使用 ReactiveObjC -- 对应的是RAC的OC版本,最新3.1.0版本. ReactiveCocoa--对应的是RAC的swift版本,最新7.1.0版本. 1.纯OC项 ...

  5. 走进VR游戏开发的世界

    http://geek.csdn.net/news/detail/76504 我们组在2014年下半年尝试开发了一款Xbox One平台的体感游戏,2015年上半年进行收尾工作的同时,结合之前积累的体 ...

  6. 在maven中引入本地jar包的方法

    一.第一种方式: 1.电脑安装maven 2.下载jar.例如 gj.jar 3.把jar随便放一个位置 4.在jar包目录下打开cmd输入: mvn install:install-file -Df ...

  7. IDEA快捷的添加包名

    Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题 2018年02月24日 17:24:49 _云卷云舒_ 阅读数:6264 标签: intellij idea 更 ...

  8. javascript的学习笔记---复习及学习

    1.javascript包含三大部分(BOM,DOM,ECMAscript) ECMAscript:规定js的语法规范 BOM:Document Object Model 给我们提供了一套完整的操作页 ...

  9. bzoj3417:[POI2013]MOR-Tales of seafaring

    传送门 这个题比较水,很容易看出 1.最短路小于d,直接看奇偶性就好了 2,最短路大于d,puts("NIE\n"); 主要就是判奇偶性的问题,将每个点拆成奇点和偶点跑bfs就行了 ...

  10. shell学习(1)

    #!/bin/bash #######read从屏幕输入######## echo "what is your name?" read PERSON echo "Hell ...