例题整理
一,
题1 1229. 日期问题
#include<iostream>
using namespace std;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int a,b,c;
bool is_leap(int date)
{
return (date%400==0)||(date%4==0&&date%100);
}
bool check(int date)
{
int year=date/10000,month=(date/100)%100,day=date%100;
days[2]=is_leap(year)?29:28;
if(!month||month>=13||!day||day>days[month]) return false;
return true;
}
bool check(int year,int month,int day)
{
return year==a&&month==b&&day==c;
}
int main()
{
scanf("%d/%d/%d",&a,&b,&c);
for(int date=19600101;date<=20591231;++date)
{
if(!check(date)) continue;
int year=date/10000,month=(date/100)%100,day=date%100;
if(check(year%100,month,day)||check(month,day,year%100)||check(day,month,year%100))
printf("%d-%02d-%02d\n", year, month, day);
}
return 0;
}
题2 1231. 航班时间
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int get_seconds(int h,int m,int s)
{
return h*3600+m*60+s;
}
int get_time()
{
string line;
getline(cin,line);
if(line.back()!=')') line+=" (+0)";
int h1,m1,s1,h2,m2,s2,d;
sscanf(line.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&d);
return get_seconds(h2,m2,s2)-get_seconds(h1,m1,s1)+d*24*3600;
}
int main()
{
int n;
scanf("%d",&n);
string line;
getline(cin,line);
while(n--)
{
int time=(get_time()+get_time())/2;
int hour=time/3600,minute=time%3600/60,second=time%60;
printf("%02d:%02d:%02d\n",hour,minute,second);
}
return 0;
}
二,
题1 1238. 日志统计
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
#define x first
#define y second
const int N=100010;
int n,d,k;
PII log[N];
int cnt[N];
bool st[N];
int main()
{
scanf("%d%d%d",&n,&d,&k);
for(int i=0;i<n;++i)
scanf("%d%d",&log[i].x,&log[i].y);
sort(log,log+n);
for(int i=0,j=0;i<n;++i)
{
while(log[i].x-log[j].x>=d) --cnt[log[j++].y];
if(++cnt[log[i].y]>=k) st[log[i].y]=true;
}
for(int i=0;i<N;++i)
if(st[i]) printf("%d\n",i);
return 0;
}
题2 1241. 外卖店优先级
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
#define x first
#define y second
const int N=100010;
int n,m,T;
int score[N],last[N];
bool st[N];
PII order[N];
int main()
{
scanf("%d%d%d",&n,&m,&T);
for(int i=0;i<m;++i)
scanf("%d%d",&order[i].x,&order[i].y);
sort(order,order+m);
for(int i=0;i<m;)
{
int j=i;
while(j<m&&order[j]==order[i]) ++j;
int t=order[i].x,id=order[i].y,cnt=j-i;
i=j;
score[id]-=t-last[id]-1;
if(score[id]<0) score[id]=0;
if(score[id]<=3) st[id]=false;
score[id]+=cnt*2;
if(score[id]>5) st[id]=true;
last[id]=t;
}
for(int i=1;i<=n;++i)
if(last[i]<T)
{
score[i]-=T-last[i];
if(score[i]<=3) st[i]=false;
}
int res=0;
for(int i=1;i<=n;++i) res+=st[i];
printf("%d",res);
return 0;
}