Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Eachof the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in thesame manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50
Sample Output
10 20 30
思路:贪心算法,没经过一个房间对应数组位加一,最后找出数组的最大值。
代码:
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
int arr[401];
int T,N,s,t;
int num;
cin>>T;
while(T--){
memset(arr,0,sizeof(arr));
cin>>N;
for(int i=0;i<N;i++){
cin>>s>>t;
if(s>t)
swap(s,t);
//注意房间的布局
if(s%2==0)
s--;
if(t%2)
t++;
for(int j=s;j<=t;j++)
arr[j]++;
num=0;
for(int k=0;k<401;k++){
if(arr[k]>num)
num=arr[k];
}
}
cout<<num*10<<endl;
}
}