当前位置: 首页> 科技> 数码 > P1167 刷题

P1167 刷题

时间:2025/7/17 15:50:28来源:https://blog.csdn.net/zhangshuangjiang/article/details/141475644 浏览次数:2次

首先必备的基础知识是闰年2月有29天

然后就是如何判断闰年

bool ru(int x) {if (x % 100 == 0) {if (x % 400 == 0)return 1;} else {if (x % 4 == 0)return 1;}return 0;
}

 然后就是整体代码

#include<bits/stdc++.h>
using namespace std;typedef long long ll;
int day[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[15], b[15], ti[5010];
ll t;
ll ans;
int n;
ll da,h,m;bool ru(int x) {if (x % 100 == 0) {if (x % 400 == 0)return 1;} else {if (x % 4 == 0)return 1;}return 0;
}int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d", &ti[i]);}sort(ti + 1, ti + 1 + n);scanf("%d-%d-%d-%d:%d", &a[1], &a[2], &a[3], &a[4], &a[5]);scanf("%d-%d-%d-%d:%d", &b[1], &b[2], &b[3], &b[4], &b[5]);
//	if(a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]&&a[4]==b[4]&&a[5]==b[5]){//10·?
//		cout<<0;
//		return 0;
//	}for(int i=a[1];i<=b[1];i++){if(ru(i)) da+=366;else da+=365;}for(int i=1;i<=a[2];i++){if(ru(a[1])&&i==2) da-=day[i]+1;//else da-=day[i];}for(int i=12;i>=b[2];i--){if(ru(b[1])&&i==2) da-=day[i]+1;//else da-=day[i];}for(int i=day[a[2]];i>=a[3];i--){da++;}for(int i=1;i<=b[3];i++){da++;}da--;t=da*1440;t=t-(a[4]-b[4])*60-(a[5]-b[5]);for(int i=1;i<=n;i++){if(t-ti[i]>=0){t-=ti[i];ans++;}}printf("%lld",ans);return 0;
}

ok了,老铁

关键字:P1167 刷题

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: