zoukankan      html  css  js  c++  java
  • BOX

    题目连接:http://acm.tju.edu.cn/toj/showp2392.html
    2392.   Box
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 846   Accepted Runs: 304    Multiple test files



    Ivan works at a factory that produces heavy machinery. He has a simple job — he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.

    Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes — he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake.

    Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.

    Input

    Input consists of six lines. Each line describes one pallet and contains two integer numbers w and h (1 ≤ wh ≤ 10 000) — width and height of the pallet in millimeters respectively.

    Output

    Write a single word "POSSIBLE" to the output if it is possible to make a box using six given pallets for its sides. Write a single word "IMPOSSIBLE" if it is not possible to do so.

    Sample InputSample Output
    1345 2584
    2584 683
    2584 1345
    683 1345
    683 1345
    2584 683
    
    POSSIBLE
    1234 4567
    1234 4567
    4567 4321
    4322 4567
    4321 1234
    4321 1234
    
    IMPOSSIBLE



    Source: Northeastern European 2004

    题解: :对面进行排序,比较相邻的两个面是否相同,当两个面相同的时候看第一个面和第三个面是否有公共边,最后看最后的面可以和前两个面连起来吗

    重复的东西可以写成函数 不易出错,

    这里注意,如果最后满足题意的有一种情况的时候,flag定义成false,有一个满足就更新成true,

    而要找所有条件都满足的时候,开始将flag定义成true,有一个不满足就更新成false

    其实刷水题还是有用的,gaga.

     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 
     5 struct pg{
     6     int x, y;
     7     bool operator < (const pg a) const {
     8         return x == a.x ? y < a.y : x < a.x;    
     9     }
    10 }p[6];
    11 bool ch(int x, int y, pg tm)
    12 {
    13     if(x > y) swap(x, y);
    14     return x == tm.x && y == tm.y; 
    15 } 
    16 
    17 int main()
    18 {
    19     while(~scanf("%d %d", &p[0].x, &p[0].y))
    20     {
    21         for(int i = 1; i < 6; i++) scanf("%d %d", &p[i].x, &p[i].y);
    22         for(int i = 0; i < 6; i++) if(p[i].x > p[i].y) swap(p[i].x, p[i].y);
    23         sort(p, p+6);
    24         if(p[0].x != p[1].x || p[0].y != p[1].y || p[2].x != p[3].x || p[2].y != p[3].y || p[4].x != p[5].x || p[4].y != p[5].y)
    25         {
    26             puts("IMPOSSIBLE");
    27             continue;
    28         }
    29         pg a = p[0], b = p[2], c = p[4];
    30         int t1, t2;
    31         bool flag = false;
    32         if(a.x == b.x && ch(a.y, b.y, c)) flag = true;
    33         if(a.x == b.y && ch(a.y, b.x, c)) flag = true;
    34         if(a.y == b.x && ch(a.x, b.y, c)) flag = true;
    35         if(a.y == b.y && ch(a.x, b.x, c)) flag = true;
    36         if(flag) puts("POSSIBLE");
    37         else puts("IMPOSSIBLE");
    38     }
    39     return 0;
    40 } 
  • 相关阅读:
    Mongo连接远程数据库
    将MongoDB服务器设置成Windows启动服务(win10)
    关于php初学者的理解!请大家浏览并指出不足!谢谢!
    python+selenium初学者常见问题处理
    极客时间测试专栏阅读总结——软件测试总体方案
    pytest 一.安装和使用入门
    软件测试工程师——你不仅仅应该会点点点
    测试电梯、杯子、桌子、洗衣机的方法
    软件测试面试-软件测试宝典
    支付测试场景
  • 原文地址:https://www.cnblogs.com/shanyr/p/4714615.html
Copyright © 2011-2022 走看看