POJ 3393.Lucky and Good Months by Gregorian Calendar题解--zhengjun

思路

那就直接摸你就好了吧。

代码

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;typedef long long ll;
struct Precision{int x;Precision(int a){x=a;}};struct SW{int x;SW(int a){x=a;}};struct SF{int x;SF(int a){x=a;}};
#define Set(x,y,z) SW(x)<<SF(y)<<z<<SW(0)
struct IO{
	#define Tp template<typename T>
	#define _D isdigit(c=gc())
	#define _A f|=eb;if(f)_R
	#define _R return *this
	#define _G p1==p2&&(p2=(p1=B)+fread(B,1,S,stdin),p1==p2)?EOF:*p1
	#define _T(x) while(st[++st[0]]=x%10+'0',x/=10)
	#define _O operator
	static const int S=1<<21;char B[S],*p1,*p2,sf,t;int st[105],H,bs,sw;bool eb,f;char nex(){return _G;}IO(){bs=6;sf=eb=sw=0;}
	IO& _O >> (char&c){_A;while(T(c=gc())){_A;}_R;}char gc(){t=(_G++);t=='\r'&&nex()=='\n'&&(gc());t==EOF&&(eb=1);return t;}
	IO& _O >> (string&s){_A;s="";char c;while(T(c=gc())){_A;}while(s+=c,!T(c=gc()));_R;}IO& _O << (Precision x){bs=x.x;_R;}
	IO& _O >> (char*c){_A;while(T(*c=gc())){_A;}while(!T(*++c=gc()));*c=0;_R;}int P(char c){return c=='\n'||c=='\r'||c==EOF;}
	IO& _O >> (double&x){_A;x=0;bool F=0;char c;while(!_D){F^=(c=='-');_A;}while(x=x*10+(c^48),_D&&(P(c),1));if(c^'.')_R;c=gc();
	double k=1;while(x+=(c^48)*(k*=0.1),_D);F&&(x=-x);_R;}void pu(int x){while(x-->0)pc(sf);}IO& _O << (SW x){sw=x.x;_R;}
	Tp IO& _O >> (T&x){_A;x=0;bool F=0;char c;while(!_D){F^=(c=='-');_A;}while(x=(x<<3)+(x<<1)+(c^48),_D);F&&(x=-x);_R;}
	IO& _O << (const string &s){int l=s.length();pu(sw-l);for(int i=0;i<l;i++)pc(s[i]);_R;}IO& _O << (const char c){pc(c);_R;}
	IO& _O << (char*c){int l=strlen(c);pu(sw-l);for(int i=0;i<l;i++)pc(c[i]);_R;}void CL(){fwrite(B,1,H,stdout);H=0;}
	IO& _O << (const char*c){int l=strlen(c);pu(sw-l);for(int i=0;i<l;i++)pc(c[i]);_R;}IO& _O << (SF x){sf=x.x;_R;}
	IO& _O << (double x){x<0&&(st[++st[0]]='-',x=-x);double t=0.5;for(int i=1;i<=bs;i++)t*=0.1;x+=t;ll y=x;_T(y);pu(sw-st[0]-
		bool(bs)-bs);while(st[0])pc(st[st[0]--]);x-=ll(x);if(bs)pc('.');for(int i=1;i<=bs;i++)pc(int(x*=10)+'0'),x-=int(x);_R;}
	Tp IO& _O << (T x){x<0&&(pc('-'),x=-x);_T(x);pu(max(sw-st[0],0));while(st[0])pc(st[st[0]--]);_R;}_O bool()const{return !f;}
	IO& getline(string&s){_A;s="";char c=gc();if(!P(c))while(s+=c,!P(c=gc()));_R;}void pc(const char c){H==S&&(CL(),0);B[H++]=c;}
	IO& getline(char*c){_A;*c=gc();if(!P(*c))while(!P(*++c=gc()));*c=0;_R;}int T(char c){return c==' '||P(c);}~IO(){CL();}
}fin,fout;
#include<iostream>
using namespace std;
#define DAY ((day+5)%7)
int T,day,ys,ms,ye,me,good,lucky;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
bool leap(int i){
	if(i<1582)return i%4==0;
	return i==1700||i%400==0||(i%100!=0&&i%4==0);
}
int to_today(int ys,int ms){
	for(int i=1;i<ys;i++)day+=365+leap(i),day%=7;
	if(ys>1752)day=(day+3)%7;
	for(int i=1;i<ms;i++){
		day+=month[i-1];
		if(leap(ys)&&i==2)day++;else if(ys==1752&&i==9)day-=11;
	}
	return day%=7;
}
int main(){
	for(fin>>T;T--;){
		day=1;good=lucky=0;fin>>ys>>ms>>ye>>me;day=to_today(ys,ms)%7;
		for(int i=ms,year=ys;i<=12;){
			if(DAY<2||DAY==6)good++;day+=month[i-1];if(leap(year)&&i==2)day++;if(year==1752&&i==9)day-=11;
			day%=7;if(DAY==6||DAY<2)lucky++;if(i==me&&year==ye)break;if(++i==13)i=1,year++;
		}
		fout<<lucky<<' '<<good<<'\n';
	}
	return 0;
}
posted @ 2022-06-11 15:32  A_zjzj  阅读(28)  评论(0编辑  收藏  举报