分考场

n个人参加某项特殊考试。
为了公平,要求任何两个认识的人不能分在同一个考场。
求是少需要分几个考场才能满足条件。

输入格式:
第一行,一个整数n(1<n<100),表示参加考试的人数。
第二行,一个整数m,表示接下来有m行数据
以下m行每行的格式为:两个整数a,b,用空格分开 (1<=a,b<=n) 表示第a个人与第b个人认识。

输出格式:
一行一个整数,表示最少分几个考场。

例如:
输入:
5
8
1 2
1 3
1 4
2 3
2 4
2 5
3 4
4 5

程序应该输出:
4

再比如:
输入:
5
10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

则程序应该输出:
5

资源约定:
峰值内存消耗 < 256M
CPU消耗 < 1000ms

请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。

所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。
注意:不要使用package语句。不要使用jdk1.7及以上版本的特性。

public class Main {
    public static void main(String[] args) {
        Scanner love=new Scanner(System.in);
        Map<Integer,List> m=new HashMap();
        List l;
        int n=love.nextInt();
        int z=love.nextInt();
        for(int i=0;i<z;i++){
            int k=love.nextInt();
            int v=love.nextInt();
            if(m.get(k)==null){
                l=new ArrayList();
            }else {
                l=m.get(k);
            }
            l.add(v);
            m.put(k,l);
        }
        int count=0;
        boolean flag=false;
        for(int i=1;i<n+1;i++){
            if(i==1) {
                count=1;
                continue;
            }
            int sum=0;
            for(int j=i-1;j>0;j--){
                List list = m.get(j);
                Iterator iterator = list.iterator();
                while (iterator.hasNext()){
                    flag=false;
                    if(i==(int)iterator.next()){
                        flag=true;
                        break;
                    }
                }
                if (flag){
                    sum++;
                }
            }
            if (sum==i-1){
                count++;
            }
        }
        System.out.println(count);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值