SGU 174.wall
题意:
判断给出的线段是否组成了多边形。
Solution:
简单题,并查集+hash
这里用map实现
code
#include <iostream>
#include <cstdio>
#include <utility>
#include <map>
using namespace std;
typedef pair<int, int> ii;
map<ii, int> f;
int fa[400009];
int n, xa, ya, xb, yb, cnt;
int Find (int x) {
if (fa[x] != x) return fa[x] = Find (fa[x]);
return x;
}
int main() {
scanf ("%d", &n);
for (int i = 1; i <= 2 * n; i++) fa[i] = i;
for (int i = 1; i <= n; i++) {
scanf ("%d %d %d %d", &xa, &ya, &xb, &yb);
ii tem1 = make_pair (xa, ya), tem2 = make_pair (xb, yb);
if (f.count (tem1) == 0 ) f[tem1] = ++cnt;
if (f.count (tem2) == 0 ) f[tem2] = ++cnt;
int x = Find (f[tem1]), y = Find (f[tem2]);
if (x != y)
fa[x] = y;
else {
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
SGU 174.wall的更多相关文章
- SGU 174 Walls
这题用并查集来做,判断什么时候形成了环即判断什么时候加入的线段两个端点原先是属于同一集合的.对于一个点,有两个坐标x,y,不好做并查集操作,于是要用map来存储,即做成map<node,int& ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- SGU 乱乱开
本解题报告 乱抄,乱写,随性随心,不喜多喷! SGU 142: 思路:一个string的字串不会超过2^20个,我们枚举出来就好了. 我出错点:数组RE #include<stdio.h> ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- gcc -Wall -pedantic -ansi(转载)
转载自R-G-Y-CQ的新浪博客 -Wall显示所有的警告信息 -Wall选项可以打开所有类型的语法警告,以便于确定程序源代码是否是正确的,并且尽可能实现可移植性. 对Linux开发人员来讲,GCC给 ...
- UVALive 2453 Wall (凸包)
题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...
- write/wall 1
linux:/opt/software/lktest/c # wallhellllllllllllllllllllooooooooooooooooo^[[AasZZZZZZ^Clinux:/opt/s ...
- Image Wall - jQuery & CSS3 图片墙效果
今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...
随机推荐
- -_-#flash播放器自适应
设置断点,几个断点下的固定布局
- Research Papers
NSE, $\bbu$ [Papers]NSE, $u$, Lorentz space [Sohr, JEE, 2001] [Papers]NSE, $u$, Lorentz space [Bjorl ...
- 选择排序(SelectSorted)
//简单的选择排序public class SelectSorted { public static void main(String[] args) { int[] array={12,24,9,7 ...
- poj 1329 Circle Through Three Points(求圆心+输出)
题目链接:http://poj.org/problem?id=1329 输出很蛋疼,要考虑系数为0,输出也不同 #include<cstdio> #include<cstring&g ...
- Ural-1018 Binary Apple Tree(树形dp+分组背包)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #i ...
- socket programming Max size of tcp/ip socket Buffer?
TCP data is buffered at both sender and receiver. The size of the receiver's socket receive buffer d ...
- Django中的Ajax
Ajax 很多时候,我们在网页上请求操作时,不需要刷新页面.实现这种功能的技术就要Ajax!(本人定义,不可迷信) jQuery中的ajax就可以实现不刷新页面就能向后台请求或提交数据的功能,我们仍然 ...
- poj 2367 Genealogical tree【拓扑排序输出可行解】
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3674 Accepted: 2445 ...
- 网络子系统42_ip协议处理函数_数据帧的接收
//向协议栈注册l3处理函数 1.1 void dev_add_pack(struct packet_type *pt) { int hash; //ptype_all ptype_base共用一把锁 ...
- JavaScript实现简单的打印功能
var printSetup = function(){ // 打印页面设置 wb.execwb(8,1); }; var printPreView = function(){ // 打印页面预览 w ...