当前位置:网站首页>AcWing 3391. 今年的第几天?(简单题)
AcWing 3391. 今年的第几天?(简单题)
2022-08-03 07:59:00 【GHOSTANDBREAD】
题目链接:3391. 今年的第几天? - AcWing题库
思路:
用前缀和预处理一下日期,对其进行一个优化,而不是单纯的暴力模拟
代码:
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int r[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sr[13], sn[13];
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
for(int i = 1; i <= 12; i ++) {
sr[i] = sr[i - 1] + r[i];
sn[i] = sn[i - 1] + n[i];
}
int y, m, d;
while(cin >> y >> m >> d) {
if((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) cout << sr[m - 1] + d << endl;
else cout << sn[m - 1] + d << endl;
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
并发之固定运行和交替运行方案
Roson的Qt之旅#104 QML Image控件
ArcEngine (3) zoom in and zoom out through the MapControl control to achieve full-image roaming
mysql服务器上的mysql这个实例中表的介绍
DeFi明斯基时刻:压力测试与启示
数据监控平台
redis AOF持久化个人理解
mysqlbinlog: unknown variable 'default-character-set=utf8'
23届微软秋招内推
FusionAccess软件架构、FusionAccess必须配置的四个组件、桌面发放流程、虚拟机组类型、桌面组类型
审批流设计
The use of the database table structure document generation tool screw
swiper分类菜单双层效果demo(整理)
基于SSM开发的的小区物业管理系统小程序源码
Daily practice of PMP | Do not get lost in the exam-8.2 (including agility + multiple choice)
Mysql的in和exists用法区别
ArcEngine(一)加载矢量数据
thop 使用心得
001-进程与线程
并发之ReentrantLock