前言
后面三题不可写,只放题,不做题解。
本赛涉及题目:
A: [Chess Tourney]C: [Two TVs]
T1 Chess Tourney
题面
原题地址: [A]
题意
有2*n个数,问能否将其分成两列使第一列的最大值小于第二列的最小值。
思路
排序一下,比较第n个数与第n+1个数就行了。
代码
#include<bits/stdc++.h>
using namespace std;
int n,a[500],i;
int main()
{
for(scanf("%d",&n),i=1;i<=2*n;i++) scanf("%d",&a[i]);
sort(a+1,a+2*n+1);
a[n]==a[n+1]?printf("NO"):printf("YES");
return 0;
}
小结
水题*1;
T2 Luba And The Ticket
题面
原题地址: [B]
题意
有六个数,你可以改变任意的数成任意的数,问最少要改变几个数能使前三个数等于后三个数。
思路
分类讨论+暴力。
代码
#include<bits/stdc++.h>
using namespace std;
int n,i,b,a[10],sum;
char c;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
for(i=1;i<=6;i++) scanf("%c",&c),a[i]=c-'0';
b=a[1]+a[2]+a[3]-a[4]-a[5]-a[6];//我们需要通过改变来使b=0;
if(b)
{
i=0;
if(b>0)//前三个大于后三个。
{
a[4]=9-a[4];
a[5]=9-a[5];
a[6]=9-a[6];
sort(a+1,a+7,cmp);//将我们能够通过改变每一个数所能使b减小的最大值排序;
while(sum<b)
{
sum+=a[++i];
}
}
else//同上;
{
b=abs(b);
a[1]=9-a[1];
a[2]=9-a[2];
a[3]=9-a[3];
sort(a+1,a+7,cmp);
while(sum<b)
{
sum+=a[++i];
}
}
printf("%d",i);
}
else printf("0");
return 0;
}
小结
水题*2。
T3 Two TVs
题面
原题地址: [C]
题意
你有两台电视和n个节目要看,每个节目有一个开始时间与结束时间,问能否将每一个节目从头放到尾。
假设用第一个电视放第i个节目,结束时间为k,接下来第一个电视只能放开始时间大于k的节目。
思路
先将节目通过开始时间排序,然后模拟每一台电视。
代码
#include<bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
int n,i,watch_time[3];
ii t[200005];
bool cmp(ii x,ii y)
{
return x.first==y.first?x.second<y.second:x.first<y.first;
}
int main()
{
watch_time[1]=watch_time[2]=-1;
for(scanf("%d",&n),i=0;i<n;i++) scanf("%d%d",&t[i].first,&t[i].second);
sort(t,t+n,cmp);
for(i=0;i<n;i++)
{
if(t[i].first>watch_time[1])
{
watch_time[1]=t[i].second;
continue;
}
if(t[i].first>watch_time[2])
{
watch_time[2]=t[i].second;
continue;
}
return 0*puts("NO");//如果两台电视都无法播放,直接输出NO;
}
printf("YES");
return 0;
}
小结
水题*3。
T4 Driving Test
题面
原题地址: [D]
题意
这题题面很清晰~~
提示:被违反的规则会无效化(一个规则无法违反两遍),不许超车可以重复叠加,在没清零的情况下如果违反,视为全都违反。
思路
一道大模拟题(限速的存储有些麻烦,可以用stack)。
代码
#include<bits/stdc++.h>
#define inf 10000000
using namespace std;
int stc[200005];//手动模拟栈;
int n,ans,nospeed=inf,unovertake,top,speed,x,i;
int main()
{
for(scanf("%d",&n),i=0;i<n;i++)
{
scanf("%d",&x);
if(x==1)
{
scanf("%d",&speed);
while(top&&stc[top]<speed)
{
ans++;
top--;
}
}
else
if(x==2)
{
if(unovertake)
{
ans+=unovertake;
unovertake=0;
}
}
else
if(x==3)
{
scanf("%d",&nospeed);
if(speed>nospeed)
{
ans++;
}
else
{
stc[++top]=nospeed;
}
}
else
if(x==4)
{
unovertake=0;
}
else
if(x==5)
{
nospeed=inf;
stc[++top]=nospeed;
}
else
if(x==6)
{
unovertake++;
}
}
printf("%d",ans);
return 0;
}
小结
水题*4。
不可做题
刷完水题,什么都不会做了~~
总结
后面三题如果有dalao会写,教一下。