题目地址:HDU 1856

水题。因为标号范围太大,而数据数仅仅有10w,所以要先进行离散化。然后就是裸的并查集了。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
int bin[100001], x[100001], y[100001], z[200001], c[200001], cnt, vis[200000];
int find1(int x)
{
return bin[x]==x?x:bin[x]=find1(bin[x]);
}
void merger(int x, int y)
{
int f1=find1(bin[x]);
int f2=find1(bin[y]);
if(f1!=f2)
bin[f2]=f1;
}
int twofen(int x)
{
int high=cnt-1, low=0, mid;
while(low<=high)
{
mid=low+high>>1;
if(c[mid]==x) return mid;
else if(c[mid]<x) low=mid+1;
else high=mid-1;
}
}
int main()
{
int n, i, max1, a, b, f1, f2;
while(scanf("%d",&n)!=EOF)
{
cnt=1;
for(i=0;i<n;i++)
{
scanf("%d%d",&x[i],&y[i]);
z[2*i]=x[i];
z[2*i+1]=y[i];
}
sort(z,z+2*n);
c[0]=z[0];
for(i=1;i<2*n;i++)
{
if(z[i]!=z[i-1])
c[cnt++]=z[i];
}
for(i=0;i<cnt;i++)
bin[i]=i;
for(i=0;i<n;i++)
{
f1=twofen(x[i]);
f2=twofen(y[i]);
merger(f1,f2);
}
memset(vis,0,sizeof(vis));
max1=-1;
for(i=0;i<cnt;i++)
{
int p=find1(bin[i]);
vis[p]++;
if(max1<vis[p])
max1=vis[p];
}
printf("%d\n",max1);
}
return 0;
}

HDU 1856 More is better(并查集+离散化)的更多相关文章

  1. HDU 1856 More is better (并查集)

    题意: 给你两个数代表这两个人是朋友,朋友的朋友还是朋友~~,问这些人组成的集合里面人最多的是多少... 思路: 属于并查集了,我用的是带路径压缩的,一个集合里面所有元素(除了根节点)的父节点都是根节 ...

  2. HDU 1856 More is better(并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ...

  3. HDU HDU1558 Segment set(并查集+判断线段相交)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一 ...

  4. hdu 1257 小希的迷宫 并查集

    小希的迷宫 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 D ...

  5. hdu 3635 Dragon Balls(并查集应用)

    Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...

  6. <hdu - 1272> 小希的迷宫 并查集问题 (注意特殊情况)

     本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 Problem Description: 上次Gardon的迷宫城堡小希玩了很久(见Probl ...

  7. HDU 4496 D-City(逆向并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后 ...

  8. HDU 3407.Zjnu Stadium 加权并查集

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 1213 - How Many Tables - [并查集模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...

随机推荐

  1. Android studio ElasticDownloadView

    找到个开源项目,地址:https://github.com/Tibolte/ElasticDownload 下载进度效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...

  2. uva 1415 - Gauss Prime(高斯素数)

    题目链接:uva 1415 - Gauss Prime 题目大意:给出一个a,b,表示高斯数a+bi(i=−2‾‾‾√,推断该数是否为高斯素数. 解题思路: a = 0 时.肯定不是高斯素数 a != ...

  3. 用"池"来提升对象的复用

    对象池化是目前常用的一种系统优化的技术.通俗的说也就是一个对象不用多次的被实例化,来消耗性能,可以把这些常用的类放入一个池中,当需要的时候在去池里去拿去,不用的时候 在放入池中.可以叫做对象池.他可以 ...

  4. jquery clone方法

    引用自http://www.w3school.com.cn/tiy/t.asp?f=jquery_manipulation_clone <html> <head> <sc ...

  5. java OOP及相关基础知识汇总(转)

    OOP 对象有三个要素 behavior 接口是怎样的,有什么方法/field可以用? state 调用方法的时候,对象会有什么反应? 只有通过调用方法才能改变一个对象的state identity ...

  6. Thinkphp框架拓展包使用方式详细介绍--验证码实例(十一)

    原文:Thinkphp框架拓展包使用方式详细介绍--验证码实例(十一) 拓展压缩包的使用方式详细介绍 1:将拓展包解压:ThinkPHP3.1.2_Extend.zip   --> 将其下的 \ ...

  7. 基于S5pv210流媒体server的实现之网络摄像头(by liukun321 咕唧咕唧)

    这里仅介绍流媒体server端的实现思路.及编码注意问题,不会贴代码的详细实现. 直接入正题先介绍一下系统硬件框架: server端连接PC机用VLC播放例如以下图: server端应用程序能够分为图 ...

  8. jquery ajax协调SpringMVCD实现局部刷新IV

    feedback.jsp: <%@ page language="java" import="java.util.*" pageEncoding=&quo ...

  9. 【web必知必会】—— 图解HTTP(转)good

    本篇总结关于http的相关知识,主要内容参考如下导图: 主要讲解的内容有: 1 URL与URI的区别. 2 请求报文与相应报文的内容. 3 GET与POST的区别. 4 http的cookie.持久化 ...

  10. Graphical Shell with WebShell - WebOS Internals

    Graphical Shell with WebShell - WebOS Internals Graphical Shell with WebShell From WebOS Internals J ...