hihocoder编程练习赛9闰秒
Posted Dirge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hihocoder编程练习赛9闰秒相关的知识,希望对你有一定的参考价值。
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<math.h> 5 #include<iostream> 6 #include<stdlib.h> 7 #include<set> 8 #include<map> 9 #include<queue> 10 #include<vector> 11 #include<bitset> 12 #pragma comment(linker, "/STACK:1024000000,1024000000") 13 template <class T> 14 bool scanff(T &ret){ //Faster Input 15 char c; int sgn; T bit=0.1; 16 if(c=getchar(),c==EOF) return 0; 17 while(c!=\'-\'&&c!=\'.\'&&(c<\'0\'||c>\'9\')) c=getchar(); 18 sgn=(c==\'-\')?-1:1; 19 ret=(c==\'-\')?0:(c-\'0\'); 20 while(c=getchar(),c>=\'0\'&&c<=\'9\') ret=ret*10+(c-\'0\'); 21 if(c==\' \'||c==\'\\n\'){ ret*=sgn; return 1; } 22 while(c=getchar(),c>=\'0\'&&c<=\'9\') ret+=(c-\'0\')*bit,bit/=10; 23 ret*=sgn; 24 return 1; 25 } 26 #define inf 1073741823 27 #define llinf 4611686018427387903LL 28 #define PI acos(-1.0) 29 #define lth (th<<1) 30 #define rth (th<<1|1) 31 #define rep(i,a,b) for(int i=int(a);i<=int(b);i++) 32 #define drep(i,a,b) for(int i=int(a);i>=int(b);i--) 33 #define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next) 34 #define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++) 35 #define mem(x,val) memset(x,val,sizeof(x)) 36 #define mkp(a,b) make_pair(a,b) 37 #define findx(x) lower_bound(b+1,b+1+bn,x)-b 38 #define pb(x) push_back(x) 39 #define lowbit(x) x&-x 40 using namespace std; 41 typedef long long ll; 42 typedef pair<int,int> pii; 43 int a[2222]; 44 int b[23]={72,81,82,83,85,92,93,94,97,112,115}; //11 45 int c[23]={72,73,74,75,76,77,78,79,87,89,90,95,98,105,108,116}; //16 46 int days[33]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 47 void gettime(int y1,int m1,int d1,int h1,int mi1,int s1,int &time1) 48 { 49 for(int i=1970;i<y1;i++){ 50 if(i%4==0&&i%100!=0||i%400==0){ 51 time1+=24*3600*366; 52 } 53 else time1+=24*3600*365; 54 time1+=a[i]; 55 } 56 57 for(int i=1;i<m1;i++){ 58 time1+=days[i]*24*60*60; 59 if(y1%4==0&&y1%100!=0||y1%400==0) 60 { 61 if(i==2)time1+=24*3600; 62 } 63 } 64 // printf(">>%d\\n",time1); 65 for(int i=1;i<d1;i++)time1+=24*3600; 66 67 int pd=0; 68 for(int i=0;i<11;i++)if(y1==1900+b[i])pd=1; 69 if(m1>6&&pd)time1++; 70 71 for(int i=0;i<h1;i++)time1+=3600; 72 for(int i=0;i<mi1;i++)time1+=60; 73 time1+=s1; 74 } 75 int main(){ 76 for(int i=1970;i<=2017;i++) 77 { 78 for(int j=0;j<11;j++)a[i]=a[i]+(1900+b[j]==i); 79 for(int j=0;j<16;j++)a[i]=a[i]+(1900+c[j]==i); 80 } 81 int y1,m1,d1,h1,mi1,s1; 82 int y2,m2,d2,h2,mi2,s2; 83 scanf("%d-%d-%d %d:%d:%d",&y1,&m1,&d1,&h1,&mi1,&s1); 84 scanf("%d-%d-%d %d:%d:%d",&y2,&m2,&d2,&h2,&mi2,&s2); 85 int time1=0,time2=0; 86 gettime(y1,m1,d1,h1,mi1,s1,time1); 87 gettime(y2,m2,d2,h2,mi2,s2,time2); 88 printf("%d\\n",time2-time1); 89 }
以上是关于hihocoder编程练习赛9闰秒的主要内容,如果未能解决你的问题,请参考以下文章
hihocoder offer收割编程练习赛13 D 骑士游历