nyoj 14 会场安排问题 java Set用法

import java.util.*;
public class Main {
public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
           int T =sc.nextInt();
           while(T-->0){
             int n=sc.nextInt();
             
            Set<F> ts=new TreeSet<F>(new SORT());
            //  F  f[] =new F[n];
             for(int i=0; i<n; i++){
//           Set<String>set = new TreeSet<String>();
//           set.add("wangshaungyuan");
//           set.add("钱书芳");
//      
//           Iterator it = set.iterator();
//           while(it.hasNext())
//           {
//        	   System.out.println(it.next());
//           }
       
                 int a=sc.nextInt();
                 int b=sc.nextInt(); 
                 F f =new F(a,b);
                 ts.add(f);                             
             }     
//             Iterator it = ts.iterator();
//             while(it.hasNext())
//             {
//            	 System.out.println(it.next());
//             }
//             System.out.println();
             F  ff[] = new F[n];
                Iterator<F> it=ts.iterator();
                int e=-1;
              while(it.hasNext()){                  
                ff[++e]=it.next();   
               
             }
                int count=1;
                int nn=ff[0].b;
                int mm;
                for(int i=0;i<n;i++){
                   mm=ff[i].a;
                    if(nn<mm){
                        nn=ff[i].b;
                        count++;
                    }
                }
                System.out.println(count);
                         
           }   
    }
}
class SORT implements Comparator<F>{

        @Override
        public int compare(F a1, F a2) {
            if(a1.b<=a2.b)
                return -1;
            return 1;
        }              
}
class  F{
    int a,b;
    F(int a,int b){
        this.a=a;
        this.b=b;
    }
    F(){}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值