因为年历是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. 大白话5分钟带你走进人工智能-第二十九节集成学习之随机森林随机方式 ,out of bag data及代码(2)

              大白话5分钟带你走进人工智能-第二十九节集成学习之随机森林随机方式 ,out  of  bag  data及代码(2) 上一节中我们讲解了随机森林的基本概念,本节的话我们讲解随机森 ...

  2. 632. Smallest Range(priority_queue)

    You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...

  3. windows 系统 GitBook生成PDF、epub报错Error during ebook generation: 'ebook-convert' 乱码

    解决方法 1. 根据你的系统下载calibre并安装 2. 右键属性打开桌面图标位置 3 .复制该路径: 4. 打开我的电脑-属性-系统-高级系统设置-环境变量,配置环境. 5. 编辑"PA ...

  4. Android近场通信---NFC基础(一)(转)

    转自 http://blog.csdn.net/think_soft/article/details/8169483 本文译自:http://developer.android.com/guide/t ...

  5. 后台管理系统·快速开发框架JSite

    平台介绍 框架基于Maven构建,拆分成多个子模块,层次结构清晰.可用于所有Web应用,如企业后台管理系统.OA系统.CMS.CRM等. 框架本身集成了最新的 Flowable工作流引擎 https: ...

  6. PostgreSQL-14-异常值处理

    -- 查看异常值CREATE TABLE outerdata(id int PRIMARY KEY,value numeric); \COPY outerdata FROM 'C:\Users\iHJ ...

  7. IP服务-6-SNMP

    SNMP(简单网络管理协议) SNMP更为正式的说法是互联网标准管理框架(Internet Standard Management Framework).在这个协议架构中.被管理的设备(SNMP代理) ...

  8. PostgreSQL-3-DDL数据定义语言

    1.创建/删除新的数据库 \l  查看现有数据库 \h CREATE DATABASE  查看CREATE DATABASE语句说明 \h DROP DATABASE 查看DROP DATABASE语 ...

  9. css-bootstrap

    CSS概览 基本的bootstrap包含三个文件,引入到html页面中 <link href="{% static 'css/bootstrap.min.css' %}" r ...

  10. GYM 101889E(dp)

    dp[i][j][k]表示第i位填数字k时,与后面的相连模数为j时,后面的数字最小填多少. 测得我提心吊胆还以为复杂度高了,结果出来46ms还是cf评测姬强啊. #pragma comment(lin ...