题意:

判断给出的线段是否组成了多边形。


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的更多相关文章

  1. SGU 174 Walls

    这题用并查集来做,判断什么时候形成了环即判断什么时候加入的线段两个端点原先是属于同一集合的.对于一个点,有两个坐标x,y,不好做并查集操作,于是要用map来存储,即做成map<node,int& ...

  2. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  3. SGU 乱乱开

    本解题报告 乱抄,乱写,随性随心,不喜多喷! SGU 142: 思路:一个string的字串不会超过2^20个,我们枚举出来就好了. 我出错点:数组RE #include<stdio.h> ...

  4. 今日SGU 5.26

    #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...

  5. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  6. gcc -Wall -pedantic -ansi(转载)

    转载自R-G-Y-CQ的新浪博客 -Wall显示所有的警告信息 -Wall选项可以打开所有类型的语法警告,以便于确定程序源代码是否是正确的,并且尽可能实现可移植性. 对Linux开发人员来讲,GCC给 ...

  7. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

  8. write/wall 1

    linux:/opt/software/lktest/c # wallhellllllllllllllllllllooooooooooooooooo^[[AasZZZZZZ^Clinux:/opt/s ...

  9. Image Wall - jQuery & CSS3 图片墙效果

    今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...

随机推荐

  1. 【转】Java ConcurrentModificationException 异常分析与解决方案--还不错

    原文网址:http://www.2cto.com/kf/201403/286536.html 一.单线程 1. 异常情况举例 只要抛出出现异常,可以肯定的是代码一定有错误的地方.先来看看都有哪些情况会 ...

  2. Linux Eclipse代码提示功能设置(Java & C/C++)

    最近在Linux下开发,由于长期使用Visual Studio 2010,对代码提示功能情有独钟,现在在Linux下,使用Eclipse做开发,当然免不了怀念Visual Studio强悍的代码提示, ...

  3. 数学(概率)CodeForces 626D:Jerry's Protest

    Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...

  4. json串的使用

    一:在C#中使用json字符串 从这里下载:http://www.newtonsoft.com/products/json/ 安装: 1.解压下载文件,得到Newtonsoft.Json.dll 2. ...

  5. HDU-4405 Aeroplane chess

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...

  6. c++异常安全和copy and swap策略

    异常安全有两个目标: 不泄露任何资源.这个通过RAII可以做到. 不破坏数据结构.这是下文要讨论的事情 异常安全有三个级别: 基本安全:异常发生后对象和数据结构还有合法状态.实现简单,应该作为最低要求 ...

  7. 数学常数e的含义

    转载:   http://www.ruanyifeng.com/blog/2011/07/mathematical_constant_e.html 作者: 阮一峰 日期: 2011年7月 9日 1. ...

  8. HTTP协议介绍(SERVLET)

    本文是servlet的入门篇,主要简单介绍下http协议 1.什么是HTTP _ 1.http协议:_1. 复杂解释:   http(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议 ...

  9. 网络子系统41_inet_peer平衡二叉树的删除

    //1.p存在左孩子,则使用p的左孩子的最右孩子替换p,然后重平衡树 //2.p不存在左孩子,则使用p的右孩子替换p,然后重平衡树 1.1 static void unlink_from_pool(s ...

  10. ORA-01858: a non-numeric character was found where a numeric was expected

    [ERROR] [2017-01-05 13:18:52,617] [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.http-bio-8080-ex ...