hdu 3172 Virtual Friends】的更多相关文章

职务地址:pid=3172">HDU 3172 带权并查集水题.每次合并的时候维护一下权值.注意坑爹的输入. . 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include…
These days, you can do all sorts of things online. For example, you can use various websites to make virtual friends. For some people, growing their social network (their friends, their friends' friends, their friends' friends' friends, and so on), h…
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3172 并查集的运用... #include<algorithm> #include<iostream> #include<cstdlib> #include<cstdio> #include<map> using std::map; using std::string; ; struct UnionFind { map<string, int&…
Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5491    Accepted Submission(s): 1519 Problem Description These days, you can do all sorts of things online. For example, you can u…
Virtual Friends Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 61   Accepted Submission(s) : 28 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description These days, you can d…
Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3677    Accepted Submission(s): 1059 Problem Description These days, you can do all sorts of things online. For example, you can u…
题目比较简单,但作为长久不写题之后的热身题还是不错的. 统计每组朋友的朋友圈的大小. 如果a和b是朋友,这个朋友圈的大小为2,如果b和c也是朋友,那么a和c也是朋友,此时这个朋友圈的大小为3. 输入t,表示接下来有t组数据. 每组数据有n组朋友关系. 接下来n行,每行一组朋友关系,然后输出这组朋友的朋友圈大小,即有多少朋友. 然后又是t组数据……(这点好坑)重复上述输入,直到数据结束. 因为最多有10^5个人,那么如果用线性字符串数组保存人名,肯定超时得不要不要的,所以要用map(每次操作时间复…
题意:人与人交友构成关系网,两个人交友,相当于两个朋友圈的合并,问每个出两人,他们目前所在的关系网中的人数. 分析:用并查集,其实就是求每个集合当前的人数.对于人名的处理用到了字典树. 注意:1.题目给出的n是指n对关系,上限有2*n个人.  2.题目很没有意思的既说了有多组数据,又要求输入组数.实际上还是多组数据. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ;…
一开始一直wa,因为第一个数字t也是多组输入. 然后一直超时,因为我用的是C++里面的cin,所以非常耗时,几乎比scanf慢了10倍,但是加上了一个语句后: std::ios::sync_with_stdio(false);                //是用来禁用cin这个兼容性的特性,禁用后就相差无几了 #include <iostream> #include <cstdio> #include <vector> #include <map> #i…
ll T; while(~scanf("%d",&T)){ while(T--) { = = ... 思路: 用秩合并,看了题解才发现 if(fx == fy)要输出当前集合的秩而不是0... #include <cstdio> #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <map&…
These days, you can do all sorts of things online. For example, you can use various websites to make virtual friends. For some people, growing their social network (their friends, their friends' friends, their friends' friends' friends, and so on), h…
http://acm.hdu.edu.cn/showproblem.php?pid=3172 题意:输出每对朋友的关系网大小 并查集的时候维护一个数组记录根节点的大小即可,水题,这题坑在T组数据这个也要读到EOF,开始莫名其妙wa... #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <algorithm> #include <…
Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 705    Accepted Submission(s): 202Special Judge Problem Description As we know, Rikka is poor at math. Yuta is worrying abou…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 基础并查集★ 1325&&poj1308 Is It A Tree? 基础并查集★ 1856 More is better 基础并查集★ 1102 Constructing Roads 基础最小生成树★ 1232 畅通工程 基础并查集★ 123…
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 基础并查集★ 1325&&poj1308 Is It A Tree? 基础并查集★ 1856 More is better 基础并查集★ 1102 Constructing Roads 基础最小生成树★ 1232 畅通工程 基础并查集★ 123…
并查集题型简单并查集1213 How Many Tables 1232 畅通工程 (杭电简单的并查集不是很多) 简单最小生成树1233 还是畅通工程 1863 畅通工程 1874 畅通工程再续 1875 继续畅通工程 1162 Eddy's picture 1102 Constructing Roads 1301 Jungle Roads(可以通过最小生成树练习并查集) 稍微有点难度并查集1272 小希的迷宫 1325 Is It A Tree? 1856 More is better 有点难度…
定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己,例如pre[1]=1(2)合并,将一个元素或者一集合(两者间有联系)合并到另外一个集合(元素)里面,谁是谁的父亲节点不需要过多在意,视题意而定.(3)查找,在合并时需要运用到查找操作,即查找该元素的父节点,尽量使用路径压缩,可以使并查集更加高效,一旦使用了路径压缩,查询时就会将该查询元素到父亲的边改为直接连…
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★1102 Constructing Roads 基础最小生成树★1232 畅通工程 基础并查集★2120 Ice_cream's world I 基础并查集★212…
Virtual Friends Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11092    Accepted Submission(s): 3221 Problem Description These days, you can do all sorts of things online. For example, you can…
这题是一个很简单额并查集的题目,首先第一步是要用map将字符串映射为整型,这样方便后面的处理,然后就是用一个rank[]数组来记录每个朋友圈的人数.之后就是简单的并查集操作了. 这里给出一组测试案例: 16Fred BarneyBarney BettyBetty WilmaAAAAA BBBBBAAAA  BBBBBAAAA Fred 输出结果应是: 234237 代码如下: #include"iostream" #include"stdio.h" #include…
八方向   深搜 #include <iostream> #include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; ][]; ]= {-,-,-,, , ,,}; ]= {-, , ,-,,-,,}; //8个方向 void dfs(int x, int y) { maps[x][y] = '*'; //变为*,相当于走过 ; i < ; i++) { int…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C…
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能超过背包的容量1-P. 在这个条件下,让装入背包的物品的总价值,也就是bag[i].[v]的和最大 bag.v是每一件物品的价值,bag.p是每件物品的体积 像上面这样想是行不通的.下面有解释 这道题麻烦的是概率这东西没法用个循环表示出来,根据我以往的经验,指望着把给出的测试数据乘上一百或者一万这种…
http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4593 Robot Description A robot is a mechanical or virtual artificial agent, usually an electro-mechanical machine that is guided by a computer program or electronic circuitry. Robots can be autonomous or…
Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 220    Accepted Submission(s): 119 Problem Description Deep neural networks (DNN) have shown significant improvements in several applic…
Acperience 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5734 Description Deep neural networks (DNN) have shown significant improvements in several application domains including computer vision and speech recognition. In computer vision, a particul…
HDU认为1>2,3>2不是树,POJ认为是,而Virtual Judge上引用的是POJ数据这就是唯一的区别....(因为这个瞎折腾了半天) 此题因为是为了熟悉并查集而刷,其实想了下其实好好利用sort应该能更简单A掉,下次有空再去试试... 题目大意:判断是否为树,so: 1,无环: 2,除了根,所有的入度为1,根入度为0: 3,这个结构只有一个根,不然是森林了:4.空树也是树,即第一次输入的两个数字为0 0则是树,其他时候输入只是结束条件 因为POJ和HDU题面一样,要求不一样,所以这题…