【每日一题】 UVA - 1587 Box 二维有点偏序的感觉
一开始用set存xjb分类讨论,然后wa,
然后简化了一点,改用vector,然wa
最后又发现没有初始化,然wa
wa了一个半小时
最后看了题解orz
然后找了一组样例把自己的代码改对了
/*
1 1
1 1
1 1
1 1
1 2
1 2
*/
正统题解:不妨设三条边为a<=b<=c, 那么对每个面(边对)sort后,必然得到 ab ab ac ac bc bc 然后照着这个序列写六个判断就好了orz
#define _CRT_SECURE_NO_WARNINGS
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
#define pb push_back #define mp make_pair
#define x first
#define y second
pair<int, int> a[];
int main() {
while (cin >> a[].x >> a[].y){ rep(i, , )scanf("%d%d", &a[i].x, &a[i].y);
rep(i, , )if(a[i].x>a[i].y)swap(a[i].x,a[i].y);
sort(a + , a + );
puts(a[] == a[] && a[] == a[] && a[] == a[] && a[].x==a[].x&&a[].y==a[].y&&a[].x==a[].y?"POSSIBLE":"IMPOSSIBLE"); }
}
/*
POSSIBLE
IMPOSSIBLE
*/
第一版代码,先判每个面出现了两遍,再把不同的三个面找出来,按有几个面是正方形分类
#define _CRT_SECURE_NO_WARNINGS
#include <cmath>
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include <map>
#include <cstring>
#include <time.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
const double pi = acos(-1.0);
const int maxn = + ;
int n,m; int main()
{ int x, y; while (cin >> x >> y){
set<int> S[];
vector < set<int>> V;
S[].insert(x), S[].insert(y);
rep(i, , ) { cin >> x >> y;
S[i].insert(x), S[i].insert(y);
}
int f[];
mmm(f, );
int vis[]; mmm(vis, );
rep(i, , )rep(j, , )if (i != j) {
if (S[i] == S[j]) { f[i] = ; if (!vis[i]&&!vis[j]) { V.push_back(S[i]); vis[j] = ; vis[i] = ;} }
}
rep(i, , )if (!f[i]) { f[] = ; }
if (f[] == ) { puts("IMPOSSIBLE"); continue; }
int cnt=;
rep(i, , )if (V[i].size() == )cnt++;
if (cnt == ) { if (V[] == V[] && V[] == V[]) puts("POSSIBLE"); else puts("IMPOSSIBLE"); continue; }
if (cnt == ) {
vector < set<int>> T;
for (auto t : V)if (t.size() == ) { T.push_back(t); }
if(*T.begin()==*T.rbegin()) { puts("POSSIBLE"); continue; }else { puts("IMPOSSIBLE"); continue; }
}
if(cnt==) { puts("IMPOSSIBLE"); continue; }
if (cnt == ) {
int ok = ;
vector < int> T;
rep(i, , )if (*V[].begin() == *V[i].begin())T.push_back(*V[i].rbegin());
else if (*V[].begin() == *V[i].rbegin())T.push_back(*V[i].begin());
rep(i, , )if (*V[].rbegin() == *V[i].begin())T.push_back(*V[i].rbegin());
else if (*V[].rbegin() == *V[i].rbegin())T.push_back(*V[i].begin());
//else ok = 0;
if(T.size()!=){ puts("IMPOSSIBLE"); continue; }
if(T.front()!=T.back()) { puts("IMPOSSIBLE"); continue; }
else { puts("POSSIBLE"); continue; }
}
}
cin >> n;
return ;
}
/* 1 1
2 1
2 1
1 1
1 1
1 1
*/
第二版代码:用vector存,并且简化了分类:要么可以 要么不可能//废话
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
int main()
{ int x, y;
while (cin >> x >> y) {
vector < vector<int>> V;
vector<int> v[];
if (x > y)swap(x, y);
v[].push_back(x); v[].push_back(y);
rep(i, , ) { cin >> x >> y;
if (x > y)swap(x, y);
v[i].push_back(x); v[i].push_back(y);
}
int f[]; int vis[]; mmm(vis, );
mmm(f, );
rep(i, , )rep(j, , )if (i != j) {
if (v[i] == v[j]) { f[i] = ; if (!vis[i]&&!vis[j]) { V.push_back(v[i]); vis[j] = ; vis[i] = ;} }
}
rep(i, , )if (!f[i]) { f[] = ; }
if (f[] == ) { puts("IMPOSSIBLE"); continue; }
int ok = ;
int t = ;
int x = ;
if (V[].front() == V[].front())t = V[].back(); else if (V[].front() == V[].back())t = V[].front(); else {
x = ;
if (V[].front() == V[].front())t = V[].back(); else if (V[].front() == V[].back())t = V[].front(); else ok = ;
}
int t2 = ;
if (t == V[x].front())t2 = V[x].back(); else if (t == V[x].back())t2 = V[x].front(); else {
ok = ;
}
if (t2 != V[].back())ok = ;
if (ok)puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
return ;
}
【每日一题】 UVA - 1587 Box 二维有点偏序的感觉的更多相关文章
- Java实习生常规技术面试题每日十题Java基础(二)
目录 1. JAVA 的反射机制的原理. 2.静态嵌套类(Static Nested Class)和内部类(Inner Class)的不同? 3.如何将String类型转化成Number类型. 4.什 ...
- BZOJ3132 上帝造题的七分钟 【二维树状数组】
题目 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的 ...
- P4514 上帝造题的七分钟(二维树状数组)
P4514 上帝造题的七分钟 二维树状数组 差分维护区间加法,区间求和 #include<cstdio> int read(){ ,f=; ') f=f&&(c!='-') ...
- UVa 11297 Census (二维线段树)
题意:给定上一个二维矩阵,有两种操作 第一种是修改 c x y val 把(x, y) 改成 val 第二种是查询 q x1 y1 x2 y2 查询这个矩形内的最大值和最小值. 析:二维线段树裸板. ...
- UVA 11297 Census ——二维线段树
[题目分析] 二维线段树模板题目. 简直就是无比的暴力.时间复杂度为两个log. 标记的更新方式比较奇特,空间复杂度为N^2. 模板题目. [代码] #include <cstdio> # ...
- 计算机二级-C语言-程序填空题-190109记录-对二维字符串数组的处理
//给定程序,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,将其余字符串右边用字符*补齐,使其与最长的字符串等长.ss所指字符串数组中共有M个字符串,且串长<N. //重难点 ...
- uva 1587(Box UVA - 1587)
题目大意是给定6个数对,每个数对代表一个面的长和宽,判断这6个面是否能构成一个长方体. 这种题一看很复杂,但是只要不想多了实际上这就是一个水题... 首先说明一下判断的思路: 1.长方体是有三个对面的 ...
- UVa 1587 Box
题意:给出6个矩形的长和宽,问是否能够构成一个长方体 先假设一个例子 2 3 3 4 2 3 3 4 4 2 4 2 排序后 2 3 2 3 3 4 3 4 4 2 4 2 如果要构成一个长方体的话, ...
- BZOJ 3132 上帝造题的七分钟(二维树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3132 题意:给出一个矩阵,两种操作:(1)将某个子矩阵的数字统一加上某个值:(2)查询某 ...
随机推荐
- React Native 设置RGBA背景色
React Native 设置RGBA背景色: 可以先用Mac自带吸色工具,获取RGB值,然后设置背景如下: backgroundColor: 'rgba(52, 52, 52, 0.8)', 透明度 ...
- Effective Java 第三版——50. 必要时进行防御性拷贝
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 译:9.使用Redis进行消息传递
本指南引导您完成使用Spring Data Redis发布和订阅通过Redis发送的消息的过程.Messaging with Redis 1. 我们将构建什么? 您将构建一个使用StringRedis ...
- 【Android】GPS定位基本原理浅析
位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能手机.掌上电脑等)的标配.而定位导航技术中,目前精度最高.应用最广泛的,自然非GPS莫属了.网络上介绍GPS原理的专业资料很多,而本文 ...
- openfire群消息投递
- 【原】在Matplotlib绘图过程中设置X轴的刻度和显示文本
使用Matplotlib进行绘图时,当x轴的数据太多的时候,就需要设置x轴的刻度和显示文本,关键代码如下: 绘图结果如下:
- Install elasticsearch-head: – for Elasticsearch 5.x
Running as a plugin of Elasticsearch Install elasticsearch-head:– for Elasticsearch 5.x:site plugins ...
- vue模板语法
Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解 ...
- 深度学习的batch_size
知乎讨论: https://www.zhihu.com/question/61607442/answer/204675996 案例一 http://www.myzaker.com/article/5a ...
- Java关键字-----------------java中synchronized关键字的用法
在java编程中,经常需要用到同步,而用得最多的也许是synchronized关键字了,下面看看这个关键字的用法. 因为synchronized关键字涉及到锁的概念,所以先来了解一些相关的锁知识. j ...