#include<iostream> using namespace std; int room1[300]; int room2[300]; void QuickSort(int a[],int low,int heigh) { if(low > heigh) return ; int i; int j; int temp; i = low; j = heigh; temp = a[i]; while(i < j) { while(i<j && a[j] > temp) j--; if(i<j) a[i++] = a[j]; while(i<j && a[i] < temp) i++; if(i<j) a[j--] = a[i]; } a[i] = temp; QuickSort(a,low,--j); QuickSort(a,++i,heigh); } int main() { int n; cin>>n; while(n--) { int nums; int cnt[500] = {0}; cin>>nums; int i; for(i=0; i<nums; i++) { cin>>room1[i]; cin>>room2[i]; if(room2[i] < room1[i]) { int temp = room1[i]; room1[i] = room2[i]; room2[i] = temp; } } int flag[500] = {0}; for(int l=1; l<400; l++) for(i=0; i<nums; i++) { if(l>room1[i] && l<room2[i]-1) cnt[l]++; if(l==room1[i] || l==room2[i]) cnt[l]++; if(room1[i]%2 == 0 && l==room1[i]-1) cnt[l]++; if(room2[i]%2 == 0 && l==room2[i]-1) cnt[l]++; if(l==room1[i] && l==room2[i]-1) cnt[l]--; } QuickSort(cnt,0,399); cout<<10 * cnt[399]<<endl; } return 0; } 将房间room1到room2连线,用一个数组的下标相当于一条棒子一样从1到399移动,当棒子与连线有交点,则加一,注意处理room1和room2刚好在棒子的两端的情况。另外也要注意一下room1和room2之间的大小关系!