注解
1、这是一个模拟题。理解题意很重要。首先要看清楚,房间总共400个,是分上下的。也就是总共200列,2行。如题目中第一个图所示。
2、在模拟过程中,要保持from比to小。然后保证同时只能有一个在移动。以下这段代码是核心:
for(int j=0; j<N; j++) {
cin>>from>>to;
if(from>to) {
swap(from, to);
}
for(int j=(from+1)/2; j<=(to+1)/2; j++) {
a[j]++;
}
}
代码
#include <iostream>
#include <cstring>
using namespace std;
const int mmax = 201;
int main() {
int T;
cin>>T;
for(int i=0; i<T; i++) {
int a[mmax];
memset(a, 0, sizeof(a));
int N;
cin>>N;
int from, to;
for(int j=0; j<N; j++) {
cin>>from>>to;
if(from>to) {
swap(from, to);
}
for(int j=(from+1)/2; j<=(to+1)/2; j++) {
a[j]++;
}
}
int ans = 0;
for(int j=0; j<mmax; j++) {
ans = max(ans, a[j]);
}
ans *= 10;
cout<<ans<<endl;
}
return 0;
}