UVaLive 6627 First Date (转换时间)
题意:给定两个日期,两种不同算闰年的方法,导致日期不同,给定那个慢的,求你求了那个快的。
析:因为算闰年的方法不同,所以我们就要先从1582算到当前时间,算出差了多少天,再加上就好。注意跨月,跨年的情况。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <stack>
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
bool is_g(int y){
if(y % 400 == 0) return true;
if(y % 100 == 0) return false;
if(y % 4 == 0) return true;
return false;
} bool is_j(int y){
return y % 4 == 0;
}
bool f(int a, int b, int c)
{
int k = 28;
if(is_g(a)) k = 29;
if(b == 2 && c <= k) return true;
else if((b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) && (c <= 31)) return true;
else if((b == 4 || b == 6 || b == 9 || b == 11) && (c <= 30)) return true;
return false;
}
int cntj[10005];
int cntg[10005]; void solve(int y, int m, int d){
int cnt = cntj[y-1] - cntg[y-1];
if(m > 2 || (m == 2 && d > 28)) cnt += is_j(y) - is_g(y); cnt += 11;
while(cnt--)
{
d++;
if(f(y, m, d)) continue;
d = 1; m++;
if(f(y, m, d)) continue;
y++; m = 1; }
printf("%d-%02d-%02d\n", y, m, d);
} int main(){
int y, m, d;
for(int i = 1584; i <= 10000; i += 4){
++cntj[i];
cntg[i] += is_g(i);
}
for(int i = 1584; i <= 10000; ++i)
cntj[i] += cntj[i-1], cntg[i] += cntg[i-1]; while(~scanf("%d-%d-%d", &y, &m, &d)){
solve(y, m, d);
}
}
UVaLive 6627 First Date (转换时间)的更多相关文章
- 微信小程序中new Date()转换时间时间格式时IOS不兼容的问题
本周写小程序,遇到的一个bug,在chrome上显示得好好的时间,一到Safari/iPhone 就报错 “invalid date”,时间格式为“2019.06.06 13:12:49”,然后利用n ...
- new Date在IE下面兼容问题
昨天碰到一个bug,用art-template模板进行渲染时候,周视图任务展示失败,都是暂无任务,我以为是模板兼容问题,但最开始我用的时候记得就是IE8的兼容性问题,引入es5-shim.min.js ...
- 18 行 JS 代码编一个倒时器
有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...
- JS 代码编一个倒时器
有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...
- ASP.NET播客(留言时间,投票IP,留言限字数,上传视频)
留言发布时间功能: 界面: 前台代码: 在Datalist控件中: 在<%#getIsDate(Convert.ToString(Eval("issuanceDate"))) ...
- iOS开发——时间格式类
目前只实现了三个类方法, 第一个获取当前时间,以字符创的形式返回,例如"201606161532" 第二个以当前时间与给定时间的时间差(秒) 第三个以当前时间与给定时间的时间差(分 ...
- Swift基础之PickerView(时间)选择器
代码讲解:(后面有额外代码讲解) 首页设计UIPickerView的样式设计: leftArray = ["花朵","颜色","形状"]; ...
- 日期类时间类,日期时间类,单例模式,装箱与拆箱,数字类随机数,BigDecimal总结
1.日期类,时间类,日期时间类 初步日期使用方法及格式转换方法(旧方法): 格式://Mon Jul 30 11:26:05 CST 2018 年月日时分秒 CST代表北 ...
- Incorrect datetime value: '' for column 'examDate' at row 1
出问题的程序:user.setCreateTime(new Date()); 控制台图片一张,问题是:Incorrect datetime value: '' for column 'createTi ...
随机推荐
- UVa 11427 (期望 DP) Expect the Expected
设d(i, j)表示前i局每局获胜的比例均不超过p,且前i局共获胜j局的概率. d(i, j) = d(i-1, j) * (1-p) + d(i-1, j-1) * p 则只玩一天就就不再玩的概率Q ...
- 从MySpace基于.NET平台的六次重构经历感受分布式
它们拥有的用户和fans之多,大家都很清楚. Myspace是一个基于.NET平台的,而Facebook更多是基于LAMP的.我们来看看MySpace配合.NET+Windows Server 200 ...
- 搜集的一些RTMP项目,有Server端也有Client端
查询一些RTMP的协议封装时找到了一些RTMP开源项目,在这里列举一下,以后有时间或是有兴趣可以参考一下: just very few of them. Red5 only contains a se ...
- 《C++ Primer 4th》读书笔记 第8章-标准IO库
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936457.html
- css的框架——base.css
一.常用的base.css文件(也是比较简略的,但按需增加) body,ul,li,ol,dl,dd,h1,h2,h3,h4,h5,h6,input,p{ margin:;} ul,ol { padd ...
- store / cache 系列
### golang go-cache An in-memory key:value store/cache (similar to Memcached) library for Go, suitab ...
- Python 3 加密简介
导读 Python 3 的标准库中是没多少用来解决加密的,不过却有用于处理哈希的库.在这里我们会对其进行一个简单的介绍,但重点会放在两个第三方的软件包:PyCrypto 和 cryptography ...
- Dubbo入门实例--转载
原文地址:http://blog.csdn.net/ruishenh/article/details/23180707?utm_source=tuicool 1. 概述 Dubbo是一个分布式服务 ...
- HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力
分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...
- 【LR】录制测试脚本中的基本菜单
学习来源: MBoo,小强老师性能测试及Loadrunner培训 ——录制测试脚本: 1.Vuser -> run-time settings ->General Run Logic : ...