An Awful Problem(水题)
来源:互联网 发布:golang syscall的用法 编辑:程序博客网 时间:2024/06/10 21:24
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3751
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其实这种模拟题找一个基点,然后两个相减就好
代码写的并不好
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <map>#include <set>#include <stack>#include <cmath>#include <string>#include <iostream>#include <string>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long longusing namespace std;int mon[13],day[40],year;bool prim[40];void get_prim(){ year=0; memset(prim,true,sizeof(prim)); prim[1]=false; for(int i=2;i<=40;i++){ if(prim[i]){ for(int j=i*i;j<=40;j+=i)prim[j]=false; } } for(int i=2;i<=31;i++) if(prim[i])day[i]+=day[i-1]+1; else day[i]=day[i-1]; for(int i=1;i<=7;i++){ if(!prim[i])continue; mon[i]=day[31]; if(i%2==0)mon[i]--; year+=mon[i]; } for(int i=8;i<=12;i++){ if(!prim[i])continue; mon[i]=day[31]; if(i%2)mon[i]--; year+=mon[i]; }}bool is_bool(int x){ if((x%4==0&&x%100!=0)||x%400==0)return true; return false;}int get_(int x,int y,int z){ int cnt=0; for(int i=0;i<x;i++){ if(is_bool(i))cnt+=year; else cnt+=year-1; } for(int i=1;i<y;i++){ if(!prim[i])continue; if(i==2&&!is_bool(x))cnt+=mon[i]-1; else cnt+=mon[i]; } if(prim[y]){ cnt+=day[z]; } return cnt;}int main(){ int T; get_prim(); //for(int i=1;i<=12;i++)printf("%d %d\n",i,mon[i]); scanf("%d",&T); for(int cas=1;cas<=T;cas++){ int y1,y2,m1,m2,d1,d2; scanf("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2); int cnt1=0,cnt2=0; cnt1=get_(y1,m1,d1-1); cnt2=get_(y2,m2,d2); printf("%d\n",cnt2-cnt1); } return 0;}
- An Awful Problem(水题)
- zoj3326 An Awful Problem
- An Awful Problem
- ZOJ3326-An Awful Problem
- ZOJ 省赛题 An Awful Problem
- 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
- zoj3326——An Awful Problem
- An Awful Problem(待改正)
- zoj 3326 An Awful Problem 日期
- 数据结构与算法——普通树的定义与C++实现
- 工程中关于class文件的参数在那块设置。
- AndroidStudio如何快速制作.so
- JavaScript 数据存储之Cookie篇
- drawRect & 内存 -> 深究
- An Awful Problem(水题)
- 由浅入深学Java Socket
- 聊聊Web App、Hybrid App与Native App的设计差异
- 用php+MySQL实现检索数据库里的内容。。。
- hdu1272 小希的迷宫--并查集
- android requestWindowFeature使用详解
- cocoaPods的使用
- drawRect 进阶
- JavaScript 跨域资源共享之基础篇