当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
酷雷曼上新6大功能,全景营销持续加码
Daily practice of PMP | Do not get lost in the exam-8.2 (including agility + multiple choice)
《剑指Offer》刷题之打印从1到最大的n位数
Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
22-08-02 西安 尚医通(02)Vscode、ES6、nodejs、npm、Bable转码器
36氪详情页AES
并发之多把锁和活跃性
DSP Trick:向量长度估算
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
线性表
随机推荐
ArcEngine(二)加载地图文档
Daily practice of PMP | Do not get lost in the exam-8.2 (including agility + multiple choice)
BOM系列之localStorage
如何在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster?
并发之多把锁和活跃性
分析型数据库性能测试总结
sqlite 日期字段加一天
ArcEngine(三)通过MapControl控件实现放大缩小全图漫游
Redis的基础与django使用redis
服务器资源监控工具-nmon、nmon_analyser
热部署系统实现
Logic Pro X自带音色库列表
用云机器/虚拟机架设方舟游戏?
Docker启动mysql
ArcEngine(四)MapControl_OnMouseDown的使用
PowerShell:执行 Install-Module 时,不能从 URI 下载
推荐系统-排序层-精排模型:LR、GBDT、Wide&Deep、DCN、DIN、DIEN、MMOE、PLE
mysqlbinlog: unknown variable 'default-character-set=utf8'
Roson的Qt之旅#103 QML之标签导航控件TabBar
MySQL or使索引失效