题目链接:http://acm.tzc.edu.cn/acmhome/game.do?&method=gameProblemDetail&gameId=1&levelId=3&number=2
#include <iostream>
#include<cstdio>using namespace std;
int main()
{ int n,m,i,j,s,r,max,temp;
cin>>n;
getchar();
while(n--)
{ int stable[200]={0};
max=0;
cin>>m;
for(i=1;i<=m;i++)
{
scanf("%d%d",&s,&r);
s=(s+1)/2;
r=(r+1)/2;
if(s>r)
{
temp=s;
s=r;
r=temp;
}
for(j=s;j<=r;j++)
{
stable[j]+=1;
}
}
for(i=0;i<200;i++)
{
if(stable[i]>max) max=stable[i];
}
cout<<10*max<<endl;
}
return 0;
}
解题:
因为400个房间中只有200个单位距离,所以拿到房间号时要除以2,根据贪心算法,每经过的房间自加一次,算出最后结果。
注意:if(s>r)
{
temp=s;
s=r;
r=temp;
}这个判断条件,不然提交会出现WA。