zoj An Awful Problem 3326
来源:互联网 发布:云上数据属于 编辑:程序博客网 时间:2024/05/16 17:48
Description
In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month was a prime number. Hiqivenfin was happy with that. But several days later, his mother modified the rule so that he could get a candy only when the day of the month was a prime number and the month was also a prime number. He felt a bit upset because he could get fewer candies. What's worse, his mother changed the rule again and he had to answer a question before he could get a candy in those days. The question was that how many candies he could get in the given time interval. Hiqivenfin wanted to cry and asked you for help. He promised to give you half of a candy if you could help him to solve this problem.
Input
There are multiple test cases. The first line of input is an integer T (0 < T <= 50), indicating the number of test cases. Then T test cases follow. The i-th line of the next T lines contains two dates, the day interval of the question. The format of the date is "yyyy mm dd". You can assume both dates are valid. Hiqivenfin was born at 1000-01-01 and would not die after 2999-12-31, so the queries are all in this interval.
Hiqivenfin didn't seem to be an earthman, but the calendar was the same as that we usually use. That is to say, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
Output
Output the number of candies Hiqivenfin could get in the time interval. Both sides of the interval are inclusive.
Sample Input
21000 01 01 1000 01 312000 02 01 2000 03 01
Sample Output
010
这个题目其实还是浙江省赛中除了那三道水题之外,我唯一能做出来的题目,惭愧,
自己实在是太水了,!!!!
这题目的意思是说这个两个日期之间包括符合月也是素数,同时日也是素数
的日子到底有多少,把所有的情况列举
一下,一个年份从这个月到那个月的,然后再减去这个月之前那些天的,
举个例子,我再算时如果是5月17日,那么
就把5月2日到5月17日的日子减去就是了,不包含5月17,然后再开始算那
些是不是一年的,把年份也算上,瑞年的
是53,平年就是52,然后算算就是了!!!!!!
#include<iostream>#include<cstdio>using namespace std;int month(int m){ if(m==2||m==3||m==5||m==7||m==11) return 1; return 0;}int day(int t){ if(t==2||t==3||t==5||t==7||t==11||t==13||t==17 ||t==19||t==23||t==29||t==31)//11个 return 1; return 0;}int year(int x){ if(x%400==0||(x%100!=0&&x%4==0)) return 1; return 0;}int main(){ int i,j,k; int a,b,c,a1,b1,c1; int t; scanf("%d",&t); int sum=0; while(t--) { sum=0; scanf("%d%d%d%d%d%d",&a,&b,&c,&a1,&b1,&c1); if(a==a1) { if(b==b1) { if(month(b)) { for(i=c; i<=c1; i++) { if(day(i)) sum++; } } } if(b<b1) { for(i=b; i<b1; i++) { if(month(i)) { if((year(a))&&(i==2)) sum=sum+10; else if((!year(a))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b)) { for(i=2; i<c; i++) { if(day(i)) sum--; } } if(month(b1)) { for(i=2; i<=c1; i++) if(day(i)) sum++; } } } if(a<a1) { for(i=a+1; i<a1; i++) if(year(i)) sum=sum+53; else sum=sum+52; for(i=b; i<12; i++) { if(month(i)) { if((year(a))&&(i==2)) sum=sum+10; else if((!year(a))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b)) for(i=2; i<c; i++) { if(day(i)) sum--; } for(i=2; i<b1; i++) { if(month(i)) { if((year(a1))&&(i==2)) sum=sum+10; else if((!year(a1))&&(i==2)) sum=sum+9; else if(i==11) sum=sum+10; else sum=sum+11; } } if(month(b1)) { for(i=2; i<=c1; i++) { if(day(i)) sum++; } } } printf("%d\n",sum); } return 0;}
- ZOJ 3326 An Awful Problem
- zoj 3326 An Awful Problem
- zoj An Awful Problem 3326
- ZOJ 3326 An Awful Problem
- ZOJ 3326 An Awful Problem
- ZOJ 3326 - An Awful Problem
- ZOJ 3326 An Awful Problem
- ZOJ 3326 An Awful Problem
- zoj 3326 An Awful Problem
- ZOJ Problem Set - 3326||An Awful Problem
- zoj 3326 An Awful Problem 日期
- ZOJ 3326An Awful Problem(模拟)
- ZOJ - 3326 - An Awful Problem 模拟
- ZOJ 3326 An Awful Problem(模拟)
- ZOJ 省赛题 An Awful Problem
- ZOJ 3326 An Awful Problem 神坑模拟
- ZOJ-3326-An Awful Problem【7th浙江省赛】【模拟】
- ZOJ 3326 An Awful Problem【时间区间天数(模拟)】
- cmd创建文件方法
- find用法例子
- Java问题解析:到底创建了几个String对象?
- (Relax 贪心1.4)POJ 2325 Persistent Numbers(使用贪心策略解决这么一个问题: 给定一个数n,求一个最小的数m,使得m的各位的乘积==n)
- java内存模型(java 并发编程基础)
- zoj An Awful Problem 3326
- centos 下安装jdk
- 软件测试中sql代码的优化
- virtualenv django
- eclipse ubuntu上快捷图标
- 异常积累:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in
- MATLAB在Ubuntu下配置到applications menu
- 顺序表的应用举例
- Mahout实例(UserCF,ItermCF,SlopOne)