ZOJ 2659 Box
来源:互联网 发布:mac命令行终端 代理 编辑:程序博客网 时间:2024/06/11 19:28
查看原题
题意
给出六块板的长宽,问是否能组成一个箱子
思路
箱子的话则必有三对相同的长宽,每对保留其中一个的长宽,然后比较三个长宽(6个数字)能否匹配。(A板1和B板1相同匹配,则B板0必和C板其中之一相同匹配,C板另一边和A板0相同匹配)
代码
#include <iostream>using namespace std;struct pallet{ int width,height;}pallets[6];int isSame(pallet a,pallet b){//两板比较是否相同 if(a.width==b.width){ if(a.height==b.height){ return 1; }else return 0; }else if(a.width==b.height){ if(a.height==b.width){ return 1; }else return 0; }else{ return 0; }}int isBox(pallet a,pallet b,pallet c){//比较三个长宽是否匹配 int flag=0; if(a.width==b.width){ if(b.height==c.height){ if(c.width==a.height){ flag=1; } }else if(b.height==c.width){ if(c.height==a.height){ flag=1; } } } else if(a.width==c.width){ if(c.height=b.height){ if(b.width==a.height){ flag=1; } }else if(c.height==b.width){ if(b.height==a.height){ flag=1; } } } return flag;}int main() { while(cin>>pallets[0].width>>pallets[0].height){ int number=0; for(int i=1;i<6;i++){ cin>>pallets[i].width>>pallets[i].height; } for(int i=0;i<6;i++){//把输入转化为小数为width,大数height if(pallets[i].width>pallets[i].height){ int n=pallets[i].width; pallets[i].width=pallets[i].height; pallets[i].height=n; } } for(int i=0;i<6;i++){//给每块板找另一半,找到就停,为下一块找 int flag=0; for(int j=i;j<6;j++){ if(i!=j&&isSame(pallets[i],pallets[j])&&pallets[j].width!=0&&flag==0){ number++;flag=1; pallets[j].width=pallets[j].height=0; } continue; } } pallet temp[3]; int step=0; for(int k=0;k<6;k++){//找出留下的三块板 if(pallets[k].width!=0){ temp[step]=pallets[k]; step++; } } for(int i=0;i<3;i++){//按width从小到大冒泡排序,width相同则按height //给height也排是为了防止24 24 22 这样特殊情况 for(int j=i;j<3;j++){ if(temp[i].width>temp[j].width){ pallet swap=temp[i]; temp[i]=temp[j]; temp[j]=swap; } if(temp[i].width==temp[j].width&&temp[i].height>temp[j].height){ pallet swap=temp[i]; temp[i]=temp[j]; temp[j]=swap; } } } if(number==3&&isBox(temp[0],temp[1],temp[2])) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; } return 0;}
0 0
- zoj 2659 Box【水】
- zoj 2659 Box
- ZOJ 2659 Box
- zoj-1319-Black Box
- ZOJ 1319 Black Box
- ZOJ - 2659 Box(差一点了,待ac)
- zoj 1251 Box of Bricks
- ZOJ 1251 Box of Bricks
- zoj 1251.Box of Bricks
- zoj 1251 Box of Bricks
- ZOJ 1251 Box of Bricks
- zoj 1251 Box of Bricks
- zoj 1251 Box of Bricks
- zoj 2010 || poj 1380 Equipment Box
- ZOJ Problem Set - 1251 Box of Bricks
- ZOJ 2010 Equipment Box(POJ 1380)(暴力离散化)
- zoj 1892 || poj 2504 || UVA 10577 Bounding box
- box
- 第五章 快速击键游戏
- ubuntu下安装Apache+PHP+Mysql
- 蓝桥杯搜索练习1
- 红宝书 第3章 整理——数据类型+函数入门
- 虚拟机中的linux可以用过ssh连接本机
- ZOJ 2659 Box
- 数据结构与算法之优先队列<九>
- Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩
- android apk获取system权限
- AES加密原理
- Spring-Hibernate分库事务实现
- 欢迎使用CSDN-markdown编辑器
- arm-linux-gcc工具链下载
- HTTP协议学习笔记一