因为年历是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实战视频-移动电商-43.详细页_补充首页跳转到详细页

    43.详细页_补充首页跳转到详细页 首页轮播点击到详细页 修改我们轮播这里的代码:SwiperDiy这个类这里的代码 return InkWell( onTap: (){ Application.ro ...

  2. Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

    一.前言 Job for mysqld.service failed because the control process exited with error code. See "sys ...

  3. Spring Boot 学习系列(07)—properties文件读取

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 传统的properties读取方式 一般的,我们都可以自定义一个xxx.properties文件,然后在工程 ...

  4. now code寒假练习赛2——处女座的砝码(找规律题+高精度题)

    #include <bits/stdc++.h> #define ll long long using namespace std; int main() { long double n ...

  5. HDU5971【瞎搞】

    题意:略(忙着准备文化课...明天期中考啊.... 思路: 正解就是染色,2-sat搞: AC代码(虽然是错误的...数据水(过踏马的也行啊,起码打脸他啊!) 4 3 1 0 1 2 2 3 3 4 ...

  6. 让你头晕的VR头显,背后发生了什么?

    随着虚拟现实渐渐兴起,国内现在做虚拟现实的厂商也增多了起来.但是我经常听到有体验者向我表示:他戴上国外大厂诸如Oculus.Sony和Valve的VR头显的时候,体验十分出色,但是戴上国产的VR头显, ...

  7. numpy windows环境下载安装

    由于numpy在多个平台下非常流行,以至于习惯WINDOWS环境下的用户可能找不到下载位置,更多的时候会下载到zip文件,然后需要安装编译(自然通不过) 1.http://www.scipy.org/ ...

  8. 洛谷P3292 [SCOI2016]幸运数字(倍增+线性基)

    传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 第一眼:这不会是个倍增LCA暴力合并线性基吧…… 打了一发……A了? 所以这真的是个暴力倍增LCA合并线性基么…… ps:据某大佬说其实可以离线之后 ...

  9. [Xcode 实际操作]九、实用进阶-(2)遍历设备(输出系统)上的所有字体

    目录:[Swift]Xcode实际操作 在实际工作中,经常需要调整界面元素的字体种类. 本文将演示输出系统提供的所有字体,方便检索和使用. 在项目导航区,打开视图控制器的代码文件[ViewContro ...

  10. 16.join 用法(拼接列表时里面必须为str类型)

    s1='alex' s2='+'.join(s1) print(s2,type(s2))#a+l+e+x <class 'str'> l1=['小红','小刚','小明'] 前提:列表中的 ...