Moving Tables

https://i-blog.csdnimg.cn/blog_migrate/0f88d1381a43a8b882b6669ab58c043d.gif

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;
        }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值