Content

输入两个数 \(m,d\),请输出 \(2017\) 年 \(m\) 月的日历【其中第一天是星期 \(d\)(如果 \(d=7\) 就是星期天)】需要印的列数。

格式见题目所述。

数据范围:\(1\leqslant m\leqslant 12,1\leqslant d\leqslant 7\)。

Solution

你们怎么都这么麻烦啊,什么循环啊,什么讨论 \(4,5,6\) 啊,这题目不很简单就完事了吗?

首先我们可以看到,这里不需要考虑闰年,所以,我们把所有月份的天数通通用一个数组保存下来:

const int mo[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

那么这样的话就可以直接调用每个月份的天数了。那么第 \(m\) 月的天数就是 \(mo_m\)。

我们又可以通过自己模拟发现,前面的一列仅有 \(7-d+1\) 天数,所以我们通过先减去第一列得到剩下的天数,也就是 \(mo_m-(7-d+1)\)。

又因为后面每列有 \(7\) 天,所以我们后面需要的列数是 \(\left\lceil\dfrac{mo_m-(7-d+1)}{7}\right\rceil\),注意因为最后的一列不一定都是 \(7\) 天,所以我们需要向上取整。

所以,答案就是 \(\left\lceil\dfrac{mo_m-(7-d+1)}{7}\right\rceil+1\)。

然而,既然这道题目的范围是如此之小,我们为什么不用打表做呢?很简单,就以生成答案的程序为 generator,直接生成出所有在这个数据范围里面的答案,然后直接输出结果就好了。

Code

#1

#include <cstdio>
#include <cmath>
using namespace std; int n, m;
const int mo[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() {
scanf("%d%d", &n, &m);
printf("%d", (int)(ceil((mo[n] - (7 - m + 1)) / 7.0)) + 1);
}

#2

Generator

#include <cstdio>
#include <cmath>
using namespace std; int n, m;
const int mo[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() {
printf("int ans[13][8] = {{0, 0, 0, 0, 0, 0, 0, 0}");
for(int i = 1; i <= 12; ++i) {
printf(", {0, ");
for(int j = 1; j <= 7; ++j) {
printf("%d", (int)(ceil((mo[i] - (7 - j + 1)) / 7.0)) + 1);
if(j != 7) printf(", ");
}
printf("}");
}
return printf("};"), 0;
}

Answer

#include <cstdio>
using namespace std; int ans[13][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 4, 5, 5, 5, 5, 5, 5}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 5, 5, 5, 5, 5, 5, 6}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 5, 5, 5, 5, 5, 5, 6}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 5, 5, 5, 5, 5, 5, 6}, {0, 5, 5, 5, 5, 5, 6, 6}, {0, 5, 5, 5, 5, 5, 5, 6}, {0, 5, 5, 5, 5, 5, 6, 6}}; int n, m; int main() {
scanf("%d%d", &n, &m);
return printf("%d", ans[n][m]), 0;
}

CF760A Petr and a calendar 题解的更多相关文章

  1. 【codeforces 760A】Petr and a calendar

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Codeforces 760A Petr and a calendar

    题目链接:http://codeforces.com/problemset/problem/760/A 题意:日历需要多少列. #include <bits/stdc++.h> using ...

  3. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集

    A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. CodeForces760A

    A. Petr and a calendar time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  5. Codeforces Round #393 (Div. 2)

    A. Petr and a calendar time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  6. CF1097B Petr and a Combination Lock 题解

    Content 有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度). 以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转 ...

  7. [LeetCode] 729. My Calendar I 731. My Calendar II 732. My Calendar III 题解

    题目描述 MyCalendar主要实现一个功能就是插入指定起始结束时间的事件,对于重合的次数有要求. MyCalendar I要求任意两个事件不能有重叠的部分,如果插入这个事件会导致重合,则插入失败, ...

  8. LightOJ 1393 Crazy Calendar(博弈)题解

    题意:r*c方格中,每个格子有一定石子,每次移动每格任意数量石子,只能向下或者向右动一格,不能移动为败 思路:显然是Nim,到右下曼哈顿距离为偶数的不用管,因为先手动一下后手动一下最后移到右下后还是先 ...

  9. CF139A Petr and Book 题解

    Content 小 P 有一本 \(n\) 页的书,现给出他一周七天每天的阅读页数,求它在星期几读完这本书. 数据范围:\(1\leqslant n\leqslant 1000\). Solution ...

随机推荐

  1. Spark SQL知识点与实战

    Spark SQL概述 1.什么是Spark SQL Spark SQL是Spark用于结构化数据(structured data)处理的Spark模块. 与基本的Spark RDD API不同,Sp ...

  2. 【JavaSE】字符编码和存储编码

    字符编码和存储编码 2019-07-15  22:34:51  by冲冲 1. 英文字母和中文汉字在不同字符集编码下的字节数不同. 英文字母 字节数 : 1; 编码:GB2312 字节数 : 1; 编 ...

  3. HelloWorld与java运行机制

    HelloWorld 新建文件夹存放代码 新建一个java文件 文件后缀为.java Hello.java 注意文件拓展名改为java文件 编写代码 public class Hello{ #类名 p ...

  4. BehaviorTree.CPP.行为树XML格式(六)

    The XML format XML模式的基础 在第一个教程中,介绍了这个简单的树. <root main_tree_to_execute = "MainTree" > ...

  5. Codeforces Round #691 (Div. 2) 题解

    A 不多说了吧,直接扫一遍求出 \(r_i>b_i\) 的个数和 \(r_i<b_i\) 的个数 B 稍微打个表找个规律就可以发现,当 \(n\) 为奇数的时候,答案为 \(\dfrac{ ...

  6. 【GS文献】基因组选择在植物分子育种应用的最新综述(2020)

    目录 1. 简介 2. BLUP类模型 3. Bayesian类模型 4. 机器学习 5. GWAS辅助的GS 6. 杂交育种 7. 多性状 8. 长期选择 9. 预测准确性评估 10. GS到植物育 ...

  7. python(3)跳过第一行(多行)读入数据

    查了下资料,常见两种办法,一是设置行号,再者是利用python自带的itertools工具. 这里推荐一种新的方法,直接使用readline()函数就搞定. 示例: 创建一个文本文件,内容如下: 1 ...

  8. 基于 Helm 快速部署 Wordpress

    Helm 是 Kubernetes 中的一个开源软件包管理工具,Rainbond 从 5.3.1 版本开始支持部署 Helm 应用.实现 Helm 应用的便捷部署,访问控制.使 Rainbond 用户 ...

  9. Python中的随机采样和概率分布(二)

    在上一篇博文<Python中的随机采样和概率分布(一)>(链接:https://www.cnblogs.com/orion-orion/p/15647408.html)中,我们介绍了Pyt ...

  10. Output of C++ Program | Set 14

    Predict the output of following C++ program. Difficulty Level: Rookie Question 1 1 #include <iost ...