盒子(Box)

2023-05-16

Box

Time limit: 3.000 seconds

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

Joe delivers pallets for Ivan. Joe is not very smart andoften makes mistakes -- he brings Ivan pallets that do not fittogether to make a box. But Joe does not trust Ivan. It alwaystakes a lot of time to explain Joe that he has made a mistake.Fortunately, Joe adores everything related to computers and sincerelybelieves that computers never make mistakes. Ivan has decided touse this for his own advantage. Ivan asks you to writea program that given sizes of six rectangular palletstells whether it is possible to make a box out of them.

Input 

Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet andcontains two integer numbers w and h ( 1$ \le$w,h$ \le$10 000) --width and height of the pallet in millimeters respectively.

Output 

For each test case, print one output line. Write a single word ` POSSIBLE' to the output file if it is possibleto make a box using six given pallets for its sides. Write a single word` IMPOSSIBLE' if it is not possible to do so.

Sample Input 


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

Sample Output 


POSSIBLE
IMPOSSIBLE
  
【分析】

      将长宽不同的矩形放在不同的数组,不同矩形的数量大于3时,将其余不同的矩形均放在同一个数组中,具体实现可查看源代码。
对于一个长方体来说,它最多可由3个不同的矩形组成即3个对面均不同,此外,它还可由2个相同的上下底面和4个相同的侧面组成,
另外还有一种情况是6个面均相同即正方体,也是特殊的长方体。
首先创建4个二维数组,数组的第一行第一列的值表示一个矩形的宽,第一行第二列的值表示这个矩形的高;同样地,第二行第一列、第二列表示第二矩形……(规定,高>宽)将不同矩形保存到不同数组。假设一个矩形与前3个数组内的矩形(前提:3个数组内均有矩形)均不同则都放在第4个数组。其实,前3个数组保存的是长方体的对面。
将输入的6个矩形保存完毕后,判断第四个数组内是否有元素,如果第第个数组有元素的话,说明这6个面不能构成长方体。(因为一个长方体最多由3个不同的矩形构成)当前3个数组中有个数组内的元素个数为奇数,同样也不能构成长方体。(想一想就知道为什么了)(如果均不为奇数,那么3个数组元素的个数可能有以下组合:[6,0,0]、[2,2,2]、[2,4,0]、[4,2,0],此外并无其他的了)
接下来通过,前3个数组内的元素个数进行分类讨论:
1、当第一个数组的元素个数为6,说明6个矩形均相同,能构成一个长方体;
2、数组元素个数均为2的情况;(将不同的宽高加入到一个不含重复元素的数组中,通过判断数组的元素个数来分析是否符合条件,当出现元素个数为3时,说明有3个不同的面并且可以形成3个对面组成长方体)
3、数组元素个数分别为2、4、0或者4、2、0(当出现这种情况时,长方体的上下地面均为正方形,如果不是正方形说明不能构成长方体)

用java语言编写程序,代码如下:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		while(input.hasNext()) {
			int[][] a = new int[6][2]; int a0 = 0;
			int[][] b = new int[6][2]; int b0 = 0;
			int[][] c = new int[6][2]; int c0 = 0;
			int[][] d = new int[6][2]; int d0 = 0;
			
			for(int i = 0; i < 6; i++) {
				int w = input.nextInt();
				int h = input.nextInt();
				
				if(w > h) {
					int t = w;
					w = h;
					h = t;
				}
				
				if(a0 == 0 || w == a[a0 - 1][0] && h == a[a0 - 1][1]) {
					a[a0][0] = w;
					a[a0][1] = h;
					a0++;
				}
				else if(b0 == 0 || w == b[b0 - 1][0] && h == b[b0 - 1][1]) {
					b[b0][0] = w;
					b[b0][1] = h;
					b0++;
				}
				else if(c0 == 0 || w == c[c0 - 1][0] && h == c[c0 - 1][1]) {
					c[c0][0] = w;
					c[c0][1] = h;
					c0++;
				}
				else {
					d[d0][0] = w;
					d[d0][1] = h;
					d0++;
				}
			}
			
			if(d0 != 0 || a0 % 2 == 1 || b0 % 2 == 1 || c0 % 2 == 1)
				System.out.println("IMPOSSIBLE");
			else {
				if(a0 == 6)
					System.out.println("POSSIBLE");
				else if(a0 == 2 && b0 == 2 && c0 == 2) {
					if(a[0][0] == a[0][1] || b[0][0] == b[0][1] || c[0][0] == c[0][1])
						System.out.println("IMPOSSIBLE");
					else {
						int[] e = new int[6];
						int start = 0;
						e[start++] = a[0][0];
						if(a[0][1] != e[0])
							e[start++] = a[0][1];
						
						start = add(e, start, b[0][0]);
						start = add(e, start, b[0][1]);
						start = add(e, start, c[0][0]);
						start = add(e, start, c[0][1]);
						if(start == 3)
							System.out.println("POSSIBLE");
						else
							System.out.println("IMPOSSIBLE");
					}
					
				} else if(a0 == 2 && b0 == 4) {
					if(a[0][0] == a[0][1] && (a[0][0] == b[0][0] || a[0][0] == b[0][1]))
						System.out.println("POSSIBLE");
					else
						System.out.println("IMPOSSIBLE");
				} else if(a0 == 4 && b0 == 2) {
					if(b[0][0] == b[0][1] && (b[0][0] == a[0][0] || b[0][0] == a[0][1]))
						System.out.println("POSSIBLE");
					else
						System.out.println("IMPOSSIBLE");
				}
				else
					System.out.println("IMPOSSIBLE");
			}
		}
	}
	
	public static int add(int[] e, int start, int temp) {
		for(int x = 0; x < start; x++) {
			if(temp == e[x])
				return start;
		}
		e[start++] = temp;
		return start;
	}
}



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

盒子(Box) 的相关文章

  • 盒子(Box)

    Box Time limit 3 000 seconds Ivan works at a factory that produces heavy machinery He hasa simple job he knocks up woode
  • 浅谈linux - virtual box设置共享文件夹

    概述 本文用于展示在virtual box虚拟机创建共享文件夹 xff0c 实现windows和ubuntu文件互传 注意 开发环境 xff1a VirtualBox 6 1 ubuntu 16 04 另外 xff0c 小编所有文章均是自己
  • CentOS在virtual box中启动后网络未连接的解决

    场景 xff1a Virtual Box虚拟机环境 xff0c 网络连接方式是Internal CentOS7系统 xff0c 启动为命令行模式 xff0c 配置静态IP xff1a 192 168 3 2 启动后网络显示未连接 解决步骤
  • 【YOLOv3 decode】YOLOv3中解码理解decode_box

    文章目录 1 解码是什么意思2 代码解读3 生成网格中心 代码详解4 按照网格格式生成先验框的宽高 代码详解5 感谢链接 1 解码是什么意思 在利用YOLOv3网络结构提取到out0 out1 out2之后 xff0c 不同尺度下每个网格点
  • 【虚拟机】win 10的virtual box打开虚拟机报VERR_MEM_INIT_FAILED

    错误信息 解决办法 进入到 控制面板 程序 程序和功能 xff1a 选择 启用或关闭 Windows 功能 xff1a 重启电脑 xff0c 重新打开virtual下的虚拟机 xff0c 能够正常启动 xff1a
  • MFC Check-box与Button结合

    在MFC中经常需要一个按钮能够实现多种功能 xff0c 这个时候可以考虑通过Check box的勾选操作来与其配合实现目标效果 首先在对话框里添加Check box xff0c 并且修改Check box的ID 双击添加好的Check bo
  • Bounding box(bbox) 预测

    在出现Bounding box预测之前 xff0c 一般都是通过滑动窗口进行目标检测 本文前两部分介绍滑动窗口算法 xff0c 这样是为了更好介绍 bounding box如何引出 为了解决什么问题而引出的 也可直接跳跃到第三部分看有关bo
  • ECCV2022_Point-to-Box Network for Accurate Object Detection via Single Point Supervision 论文阅读

    ECCV2022 P2BNet 论文阅读 文章目录 ECCV2022 P2BNet 论文阅读0 Abstract 0 1 MIL multiple instance learning 多示例学习 1 Introduction 1 0 WSO
  • white/black-box attack(黑盒白盒攻击基础)

    基本概念 攻击方法分类标准 xff1a 假正性攻击 false positive 与伪负性攻击 false negative 假正性攻击 xff1a 原本是错误的但被被攻击模型识别为正例的攻击 eg 一张人类不可识别的图像 xff0c 被D
  • css流体布局下发宽度分离原则与box-sizing的使用

    学习完了CSS世界的总结 因为默认的box sizing 为content box宽度作用在内容 所以当出现 box width 100px border 1px solid red 或 box width 100px padding 20
  • 常见的3d bounding box标注工具

    0 简介 对于3d bounding box而言 xff0c 近几年随着自动驾驶的火热 xff0c 其标注工具也日渐多了起来 xff0c 本篇文章不讲具体的算法 xff0c 这里主要聚焦于这些开源的3d bounding box标注工具 x
  • Virtual Box+Ubuntu20.04+ROS2 Foxy配置

    ROS从最早的正式版本Box Turtle到现在也十几年了 而ROS2出来也挺久了 xff0c 一直没机会看看 好久也没弄ROS xff0c 这几天捣鼓了捣鼓 目录 1 Virtual Box安装Ubuntu20 04 2 ROS2 Fox
  • 深度学习笔记1:end-to-end、anchor box解释、人体检测代码

    SSD xff08 SSD Single Shot MultiBox Detector xff09 是采用单个深度神经网络模型实现目标检测和识别的方法 该方法是综合了Faster R CNN的anchor box和YOLO单个神经网络检测思
  • ROS 与 Box Turtle、C Turtle、Indigo Igloo 、Jade Turtle 、Kinetic Kame 、Melodic Morenia、Noetic Ninjemys关系

    如果没有错的话相当于这个些都是ros的版本 xff0c 就是不同时期叫的名字不一样 xff0c 用于区别不同的版本 因为也是初学者 xff0c 都还没入门 xff0c 也是网上找的资料 xff0c 并根据自己的理解写的 xff0c 如果有错
  • CSS3 box-sizing 属性

    CSS3 box sizing 属性 常规盒模型 内容区 padding border margin 如果在页面中设置100100的div 那么padding会撑大div 并且border也是在100100的基础上面进行增加像素的 box
  • matlab通过两点画线问题&&plot,line的用法和区别。

    先马 1 LINE并不等同于PLOT 我查过HELP 很多属性不同 2 对与外框的问题 PLOT可以用法BOX控制 LINE无外框 3 图形删除的问题 PLOT可用HOLD ON或OFF控制 LINE要是用DELET 因此建议使用PLOT
  • Tkinter:如何创建选择框

    I need to create a choice box where i can click on arrow and it give me list of choices And if i click on one of them it
  • Box.COM 与 Android 应用程序集成-OAuthActivity-NullpointerException?

    我正在整合BOX COM与我的 android 应用程序 所以我正在使用BoxAndroidLibraryV2 and BoxJavaLibraryV2与我的申请 我可以运行示例 Android 应用程序BoxSDKSample 因此 我从
  • 如何消除 Spotfire 箱形图中的异常值

    提前感谢您的帮助 问候 拉杰 将值添加到MAX 即使可能 值也会扭曲数据 不过 有两种技巧可以做到这一点 右键单击 gt 属性 gt Y 轴 gt 设置MIN范围值和MAX将值范围设置为可以消除所有异常值的值 这实际上只适用于所有值都彼此接
  • Nodejs:如何向浏览器发送可读流

    如果我查询框 REST API 并返回可读流 处理它的最佳方法是什么 怎么发送到浏览器呢 免责声明 我对流和缓冲区很陌生 所以其中一些代码非常理论化 你能在响应中传递readStream并让浏览器处理它吗 或者您是否必须将块流式传输到缓冲区

随机推荐

  • 找新朋友

    1079 找新朋友 分数 1 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 简单数学题公约数 题目描述 新年快到了 xff0c 天勤准备搞一个聚会 xff0c 已经知道现有会员N人 xff0c
  • 生物节律

    1084 生物节律 分数 2 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 数学题 题目描述 有些人相信 xff0c 人从出生开始就有三个生物周期 这三个生物周期分别是体力 xff0c 情绪和
  • 鸡兔同笼

    鸡兔同笼 已知鸡和兔的总数量为n xff0c 总腿数为m 输入n和m xff0c 依次输出鸡的数目和兔的数目 如果无解 xff0c 则输出No answer 样例输入 xff1a 14 32 样例输出 xff1a 12 2 样例输入 xff
  • 赌徒

    1097 赌徒 分数 2 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 查找二分查找 题目描述 有n个赌徒打算赌一局 规则是 xff1a 每人下一个赌注 xff0c 赌注为非负整数 xff0c
  • 排列(permutation)

    排列 xff08 permutation xff09 用1 2 3 xff0c xff0c 9组成3个三位数 abc xff0c def 和 ghi xff0c 每个数字恰好使用一次 xff0c 要求 abc def ghi 61 1 2
  • SQL Server Management Studio 使用方法手记

    本方法只记录自己的操作方法 xff0c 仅供参考 一 下载安装 SQL Server Management Studio V15 0 18424 0 xff0c 链接 xff1a https download csdn net downlo
  • 蛇形填数(矩阵)

    蛇形填数 在 n x n 方针里填入 1 2 xff0c xff0c n x n xff0c 要求填成蛇形 例如 xff1a n 61 4时方阵为 xff1a 10 11 12 1 9 16 13 2 8 15 14 3 7 6 5 4 上
  • WERTYU

    Problem 1343 WERTYU Time Limit 1000 mSec Memory Limit 32768 KB Problem Description A common typing error is to place the
  • 分子量(Molar Mass)

    Molar mass Time limit 3 000 seconds An organic compound is any member of a large class of chemical compounds whose molec
  • 数数字(Digit Counting)

    Digit Counting Time limit 3 000 seconds Trung is bored with his mathematics homeworks He takes a piece of chalk and star
  • 周期串(Periodic Strings)

    周期串 Periodic Strings 如果一个字符串可以由某个长度为k的字符串重复多次得到 xff0c 则称该串以k为周期 例如 xff0c abcabcabcabc以3为周期 xff08 注意 xff0c 它也以6和12为周期 xff
  • 谜题(Puzzle)

    Puzzle Time limit 3 000 seconds Puzzle A children 39 s puzzle that was popular 30 years ago consisted of a 5x5 framewhic
  • 纵横字谜的答案(Crossword Answers)

    Crossword Answers Time limit 3 000 seconds Crossword Answers A crossword puzzle consists of a rectangular grid of black
  • DNA序列(DNA Consensus String)

    DNA Consensus String Time limit 3 000 seconds Figure 1 DNA Deoxyribonucleic Acid is the molecule which contains the gene
  • 古老的密码(Ancient Cipher)

    Ancient Cipher Time limit 3 000 seconds Ancient Roman empire had a strong governmentsystem with various departments incl
  • Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    原文转载自 sunny2038 的CSDN博客文章 原文地址 最近在看Java xff0c 在编译写书上一个例子时 xff0c 由于书上的代码只有一部分 xff0c 于是就自己补了一个内部类 结果编译时出现 xff1a No enclosi
  • 瑞星微开发工具下载镜像的配置方法?

    如何根据 parameter txt 建立配置表 xff1f 首先我们来看下 parameter txt 的内容 xff1a CMDLINE mtdparts 61 rk29xxnand 0x00002000 64 0x00004000 u
  • 特别困的学生(Extraordinarily Tired Students)

    Extraordinarily Tired Students Time limit 3 000 seconds When a student is too tired he can 39 t help sleeping in class e
  • 骰子涂色(Cube painting)

    Cube painting We have a machine for painting cubes It is supplied with three different colors blue red and green Each fa
  • 盒子(Box)

    Box Time limit 3 000 seconds Ivan works at a factory that produces heavy machinery He hasa simple job he knocks up woode