T1
考场代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int Q;
int const bcr=1461,year=365,ryear=366,fenjie=1721423,fenjie2=2299160;
int const month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
inline int read(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
void workg(int r){
int ansy=1582,ansm=10,ansd=15,round=0,lround=0,mround=0;
int const lbcr=146097,mbcr=36524;
r-=fenjie2;
if(r<=17){
printf("%lld %lld %lld\n",ansy,ansm,ansd+r-1);
}else if(r>17 && r<=78){
r-=17+1;
for(int i=11;i<=12;i++){
if(r>=month[i]){
r-=month[i];
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}else if(r>78 && r<=443){
ansy=1583;r-=78+1;
for(int i=1;i<=12;i++){
if(r>=month[i]){
r-=month[i];
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}else if(r>443 && r<=809){
r-=443+1;
ansy=1584;
for(int i=1;i<=12;i++){
if(r>=month[i]){
r-=month[i];
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}else if(r>809){
bool rf=0;
r-=809+1;
ansy=1585,ansm=1,ansd=1;
lround=r/lbcr;
r%=lbcr;ansy+=lround*400;
mround=r/mbcr;
r%=mbcr;ansy+=mround*100;
round=r/bcr;
r%=bcr;ansy+=round*4;
if(r>=3*year){
r-=3*year;ansy+=3;
if(round==24 && mround!=3)rf=0;
else rf=1;
}else{
ansy+=r/year;r%=year;
rf=0;
}
for(int i=1;i<=12;i++){
if(r>=month[i]){
r-=month[i];
if(i==2 && rf)r-=1;
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}
return;
}
void work(int r){
int ansy=4713,ansm=1,ansd=1,round=0;
bool rf=0;
//cout<<"r"<<r<<endl;
if(r<=fenjie){
round=r/bcr;
ansy-=round*4;
r%=bcr;
if(r>=ryear){
ansy--,r-=ryear;
if(r>=year){
ansy-=r/year;
r%=year;
}
}else{rf=1;}
for(int i=1;i<=12;i++){
if(r>=month[i]){
r-=month[i];
if(i==2 && rf)r-=1;
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld BC\n",ansd,ansm,ansy);
return;
}
}
}else{
if(r>fenjie2){
workg(r);
return;
}
r-=fenjie+1;
//printf("gong: %lld\n",r);
ansy=1,ansm=1,ansd=0;
round=r/bcr;
ansy+=round*4;
r%=bcr;
if(r>=3*year){
r-=3*year;ansy+=3;
rf=1;
}else{
ansy+=r/year;r%=year;
rf=0;
}
for(int i=1;i<=12;i++){
if(r>=month[i]){
r-=month[i];
if(i==2 && rf)r-=1;
}else{
ansm=i;
ansd=r%month[i]+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}
}
signed main(){
// freopen("julian.in","r",stdin);
// freopen("julian.out","w",stdout);
Q=read();
for(int i=1;i<=Q;i++){
int r=read();
work(r);
}
return 0;
}
AC代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int Q;
int const bcr=1461,year=365,ryear=366,fenjie1=1721423,fenjie2=2299160,fenjie3=2299238;
int const month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
inline int read(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
void work(int r){
int ansy,ansm,ansd;
if(r<=fenjie1){
int L=0,R=4712,m,d;
while(L<R){
m=(L+R+1)>>1;
d=year*m+(m+3)/4;
if(r<d)R=m-1;
else L=m;
}
d=year*L+(L+3)/4;
r-=d;ansy=4713-L;
for(int i=1;i<=12;i++){
int mon=month[i];
if(i==2 && (ansy-1)%4==0)mon++;
if(r>=mon){
r-=mon;
}else{
ansm=i;
ansd=r%mon+1;
printf("%lld %lld %lld BC\n",ansd,ansm,ansy);
return;
}
}
}else if(r>fenjie1 && r<=fenjie2){
r-=fenjie1+1;
int L=0,R=1581,mid,d;
while(L<R){
mid=(L+R+1)>>1;
d=year*mid+mid/4;
if(r<d)R=mid-1;
else L=mid;
}
ansy=1+L;
r-=year*L+L/4;
for(int i=1;i<=12;i++){
int mon=month[i];
if(i==2 && ansy%4==0)mon++;
if(r>=mon){
r-=mon;
}else{
ansm=i;
ansd=r%mon+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}else if(r>fenjie2 && r<=fenjie3){
r-=fenjie2+1;
ansy=1582,ansm=10,ansd=15;
if(r<=16){
printf("%lld %lld %lld\n",ansd+r,ansm,ansy);
return;
}else{
r-=16+1;
for(int i=11;i<=12;i++){
int mon=month[i];
if(i==2 && ansy%4==0)mon++;
if(r>=mon){
r-=mon;
}else{
ansm=i;
ansd=r%mon+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}
}else{
r-=fenjie3+1;
int L=0,R=1000000000,mid,d;
while(L<R){
mid=(L+R+1)>>1;
d=year*mid+(mid+2)/4-(mid+100-18)/100+(mid+400-18)/400;
if(r<d)R=mid-1;
else L=mid;
}
ansy=1583+L;
r-=year*L+(L+2)/4-(L+100-18)/100+(L+400-18)/400;
bool rf;
for(int i=1;i<=12;i++){
int mon=month[i];
if(i==2 && ansy%4==0)mon++;
if(i==2 && ansy%100==0)mon--;
if(i==2 && ansy%400==0)mon++;
if(r>=mon){
r-=mon;
}else{
ansm=i;
ansd=r%mon+1;
printf("%lld %lld %lld\n",ansd,ansm,ansy);
return;
}
}
}
}
signed main(){
//freopen("julian.in","r",stdin);
//freopen("julian.out","w",stdout);
Q=read();
for(int i=1;i<=Q;i++){
int r=read();
work(r);
}
return 0;
}
T2
考场代码
#include<bits/stdc++.h>
using namespace std;
int const MAXN=1e6+10;
int n,m,c,k;
unsigned long long a,zong;
int vis[70];
inline int read(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
inline unsigned long long readull(){
unsigned long long x=0,f=1;char c=getchar();
while(!isdigit(c)){c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
struct sss{
int p,q;
}s[MAXN];
map<int,bool>Map;
vector<int>vec[MAXN];
int main(){
//freopen("zoo.in","r",stdin);
//freopen("zoo.out","w",stdout);
n=read(),m=read(),c=read(),k=read();
for(int i=1;i<=n;i++){
a=readull();
zong|=a;
}
for(int i=1;i<=m;i++){
s[i].p=read(),s[i].q=read();
vis[s[i].p]=1;vec[s[i].p].push_back(s[i].q);
}
for(int i=0;i<k;i++){
if((1<<i) & zong && vis[i]==1){
vis[i]=2;
for(int j=0;j<vec[i].size();j++)Map[vec[i][j]]=1;
}
}
int cnt=0;
for(int i=0;i<k;i++){
if(vis[i]==0 || vis[i]==2)continue;
cnt++;
bool flag=0;
for(int j=0;j<vec[i].size();j++){
if(Map.find(vec[i][j])==Map.end()){flag=1;break;}
}
if(!flag){vis[i]=2;cnt--;}
}
unsigned long long ans=(unsigned long long)pow(2,k-cnt);
cout<<(ans-n)<<endl;
return 0;
}
AC代码
#include<bits/stdc++.h>
using namespace std;
int const MAXN=1e6+10;
int n,m,c,k;
unsigned long long a,zong;
int vis[70];
inline int read(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
inline unsigned long long readull(){
unsigned long long x=0,f=1;char c=getchar();
while(!isdigit(c)){c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
struct sss{
int p,q;
}s[MAXN];
vector<int>vec[MAXN];
int main(){
//freopen("zoo.in","r",stdin);
//freopen("zoo.out","w",stdout);
n=read(),m=read(),c=read(),k=read();
for(int i=1;i<=n;i++){
a=readull();
zong|=a;
}
for(int i=1;i<=m;i++){
s[i].p=read(),s[i].q=read();
vis[s[i].p]=1;
}
for(int i=0;i<k;i++){
if(((1ull<<i) & zong) && vis[i]==1){
vis[i]=2;
}
}
int cnt=0;
for(int i=0;i<k;i++){
if(vis[i]==1)cnt++;
}
unsigned long long ans=(unsigned long long)pow(2,k-cnt);
if(k==64 && cnt==0 && n==0)printf("18446744073709551616\n");
else cout<<(ans-n)<<endl;
return 0;
}