Fork me on Gitee

笔试

制造纸箱

时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB

题目描述:

一个长方体纸箱由六个面构成。

现在给出六块纸板的长和宽,请你判断能否用这六块纸板构成一个长方体纸箱。

输入

第一行包含一个整数T,表示测试数据组数。

1 <= T <= 10

对于每组测试数据包含六行,每行包含两个整数h, w,表示一块纸板的长和宽。

1 <= h, w <= 104

输出

对于每组测试数据输出一行。如果能构成纸箱则输出POSSIBLE,否则输出IMPOSSIBLE。

样例输入

2
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234

样例输出

POSSIBLE
IMPOSSIBLE


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class S6 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n;
        n = in.nextInt();
        in.nextLine();
        HashMap<Node, Integer> map = new HashMap<>();
        int k=0;
        for (int i = 0; i < (n * 6)-1; i++) {
            String[] split = in.nextLine().split(" ");
            int r1 = Integer.parseInt(split[0]);
            int r2 = Integer.parseInt(split[1]);
            if (r1 > r2) {
                int temp = r1;
                r1 = r2;
                r2 = temp;
            }
            Node node = new Node();
            node.h = r1;
            node.w = r2;
            if (map.get(node) != null) {
                map.put(node, 2);
            }else {
                map.put(node, 1);
            }
            if(k==5) {
                k=0;
                Iterator<Entry<Node, Integer>> it = map.entrySet().iterator();
                int count=0;
                while(it.hasNext()){
                    Entry<Node, Integer> next = it.next();
                    Integer value = next.getValue();
                    if(value==2) {
                        count++;
                    }
                }
                if(count==3) {
                    System.out.println("POSSIBLE");
                }else {
                    System.out.println("IMPOSSIBLE");
                }
                map.clear();
            }
            k++;
        }
    }
}

class Node {
    int h;
    int w;
    int count = 0;

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + h;
        result = prime * result + w;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Node other = (Node) obj;
        if (h != other.h)
            return false;
        if (w != other.w)
            return false;
        return true;
    }
}




列车排座2

时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB

题目描述:

有n位乘客乘坐一列列车,列车一共会依次经过105个站点,从1到105编号。

我们已知每一位乘客的上车站点和下车站点,但是不知道这些乘客的订票顺序。

当一位乘客订票时,他会在当前还空余的座位中选择一个他喜欢的位置,但是我们不知道乘客的喜好,所有他具体订哪个位置我们是不知道的。

现在你需要计算列车最少需要安排多少座位,可以使得无论乘客的订票情况和顺序是怎么样的,所有乘客都有座位可以坐。

举个例子,有三位乘客:

A:1→2  si--->ti

B:2→3 si--->ti

C:1→3 si--->ti

若订票顺序是A, C, B,那么只需要两个座位就一定能满足。当A订票时,他会选择一个座位,当C订票时,可用座位只剩下一个,他会订这个剩余的座位,当B订票时,可用座位也只有一个,他会订这个座位(即最开始A的那个座位);

若订票顺序是A, B, C,那么有可能会需要三个座位,A订了一个座位,B订了与A不同的座位,此时C来订票时他只能订第三个座位。

所以对于这组例子,答案是3。

输入

第一行包含一个整数n,表示乘客的数量。

1 <= n <= 1000

接下来n行每行包含两个整数si,ti,表示第i位乘客的上车站点和下车站点。

1 <= si < ti <= 105

输出

输出对应的答案。

样例输入

10
84 302
275 327
364 538
26 364
29 386
545 955
715 965
404 415
903 942
150 402

样例输出

6

暂时没有思路


posted @ 2020-04-18 21:23  ---dgw博客  阅读(339)  评论(0编辑  收藏  举报