May Day Holiday【The 12th Zhejiang Provincial Collegiate Programming Contest】
来源:互联网 发布:手机淘宝5.6.0 编辑:程序博客网 时间:2024/05/22 22:56
Click to view the problem
题意: Marjar University 放五一假期,照常的话五一会放五天的假。但会和周末撞在一起。比如5.1是星期一,就会从4.29一直放假到5.7 总共9天。现在给你一个年份,求出这一年五一会放几天假。
思路:主要问题就是确定某一年的五月一号是星期几。所以就需要用到一个公式:s=y-1+(y-1)/4-(y-1)/100+(y-1)/400+days. 其中y是年份,days顾名思义,是这一年到五月一所有的天数,手算非闰年是121天,闰年是122天.求的s在对7取余加一就是星期。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;int year;//求是否是闰年int IsLeapYear(){ if((year%4==0&&year%100!=0)||(year%400==0)) return 1; else return 0;}//求第m月的天数int month_day(int m){ int mon_day[]= {31,28,31,30,31,30,31,31,30,31,30,31}; if(IsLeapYear()&&m==2){ return 29;} else return(mon_day[m-1]);}//求总天数int DaySearch(){ int c=0; int s; int m; for(m=1; m < 5; m++) c=c+month_day(m); c=c + 1; //printf("%d\n",c); s=year-1+(year-1)/4-(year-1)/100+(year-1)/400+c; return s % 7;}int solve(int a){ int f, k; k = DaySearch(); //printf("%d\n", k); if(k > 2) //如果是在星期二以后,就只有五天 f = 5; if(k == 2 || k == 0) //如果是星期二或者星期天,那么有6天 f = 6; if(k == 1) //如果是星期一,就有九天 f = 9; return f;}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d", &year); printf("%d\n", solve(year)); } return 0;}
0 0
- May Day Holiday【The 12th Zhejiang Provincial Collegiate Programming Contest】
- ZOJ 3876 May Day Holiday (The 12th Zhejiang Provincial Collegiate Programming Contest)
- The 12th Zhejiang Provincial Collegiate Programming Contest
- The 12th Zhejiang Provincial Collegiate Programming Contest - A
- The 12th Zhejiang Provincial Collegiate Programming Contest - G
- The 12th Zhejiang Provincial Collegiate Programming Contest - H
- The 12th Zhejiang Provincial Collegiate Programming Contest - J
- The 12th Zhejiang Provincial Collegiate Programming Contest - L
- Lunch Time【The 12th Zhejiang Provincial Collegiate Programming Contest】
- The 12th Zhejiang Provincial Collegiate Programming Contest - D
- The 12th Zhejiang Provincial Collegiate Programming Contest(部分)
- The 12th Zhejiang Provincial Collegiate Programming Contest
- (The 11th Zhejiang Provincial Collegiate Programming Contest )What day is that day?
- The 11th Zhejiang Provincial Collegiate Programming Contest--- What day is that da
- The 7th Zhejiang Provincial Collegiate Programming Contest
- The 6th Zhejiang Provincial Collegiate Programming Contest
- The 8th Zhejiang Provincial Collegiate Programming Contest / L - Javabeans
- The 8th Zhejiang Provincial Collegiate Programming Contest / M - Median
- 12th浙江省省赛 B题 Beauty of Array
- 用三个步骤实现响应式网页设计
- npm基础
- tab的实现微信界面
- 第十章 Introducing Python Statements
- May Day Holiday【The 12th Zhejiang Provincial Collegiate Programming Contest】
- C++文件操作(二)
- ubuntu安装python-sicpy包依赖的问题解决
- Django教程
- window平台下mongodb权限设置
- 吹泡泡之路(2015.4.25)
- 基于c#的IE 代理服务器设置
- java+jsp网页制作总结(2)
- MySQL 最基本的SQL语法,语句