杭电1856More is better
求大神指点杭电1586more is better,答案对,就是超时(⊙o⊙)求指点
More is better
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 19936 Accepted Submission(s): 7313
Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
#include <iostream> using namespace std; int arr[10000001] ; int num[10000001] ; int Max; inline int find(int r) {while(r!=arr[r])r=arr[r];return r; } inline void judge(int a,int b) {int x,y;x=find(a);y=find(b);if(x!=y){arr[y]=x;num[x]=num[y]+num[x];num[y]=num[x];if(num[y]>Max)Max=num[y];} } inline void Init() {for(int i=1;i<= 10000001 ;i++){arr[i]=i;num[i]=1;} } int main() {int N,a,b;while (cin>>N){Init();Max=num[1];while(N--){cin>>a>>b;judge(a, b);}cout<<Max<<endl;}return 0; }
杭电1856More is better相关推荐
- 【杭电ACM】1097 A hard puzzle
[杭电ACM]1097 A hard puzzle http://acm.hdu.edu.cn/showproblem.php?pid=1097 先用int手写了算法结果竟然wrong answer ...
- 【ACM】杭电OJ 1106 函数atoi
函数atoi是把字符串转化成整数的函数,头文件为 #include "stdlib.h" e.g. 运行环境:Dev-C++ 5.11 杭电1106 调用了sort函数,运行的时间 ...
- 【ACM】杭电OJ 2037
题目链接:杭电OJ 2037 先把b[i]进行排序,然后,b[i]与a[i+1]进行比较. #include <iostream> #include <cstdio> #inc ...
- 【ACM】杭电OJ 2020(排序)
题目链接:杭电OJ 2020 排序可以有冒泡排序,选择排序,或者直接调用函数. 下面是选择排序: #include <stdio.h> #include <math.h> in ...
- 【ACM】杭电OJ 2018
题目链接:杭电OJ 2018 从n>4开始,每一年的牛的数量=前一年的牛的数量+三年前的牛的数量 问:为什么是三年前? 答:假设三年前有一头小牛出生,出生的那一年即为第一年,到了第四年,即三年后 ...
- 【ACM】杭电OJ 1005
题目链接:杭电OJ 1005 超时代码如下(而且开辟的数组空间大小不够): #include <stdio.h> int m[100000]; int f(int n,int a,int ...
- 【ACM】杭电OJ 1004
题目链接:杭电OJ 1004 运行环境:Dev-C++ 5.11 思路: 先把先把num数组全部赋值为1:第一个颜色单独输入,从第二个开始,需要与前面的进行比较,如果前面有相同的颜色,则在目前的nu ...
- 【ACM】杭电OJ 2012。
题目链接:杭电OJ 2012 思路很简单,但是有一种高效算法显示编译错误,不知道为什么 运行环境:VS2017 AC代码: #include <stdio.h> #include < ...
- 【ACM】杭电OJ 1003。
运行环境VS2017 题目链接:杭电OJ 1003 主要思想是: 用d[i]来存放前i项中最大的和,得到end,然后再倒推,得起始的位置begin 然而在程序42行的疑问,大家可以讨论一下吗???? ...
最新文章
- Python OS模块使用汇总
- python数据展示平台_Python获取各大地图平台经纬度数据,哪家的数据最准确?
- JavaScript 仿LightBox内容显示效果
- 英文文章如何进行略读
- UEFI下面安装win7+Xubuntu18.10双系统
- 剑指offer之矩阵中的最短路径
- 【剑指Offer学习】【面试题22:栈的压入、弹出序列】
- Android自定义View【实战教程】3⃣️----Paint类、Path类以及PathEffect类详解
- 镜像文件下载及VM部署win xp 保姆级教程
- 吃鸡显示连接服务器超时,吃鸡 怎么显示连接超时 | 手游网游页游攻略大全
- pdf转jpg在线转换的方法分享
- PS去除图片中文字的方法详细图文教程
- 用银行卡号查相应的归属银行,卡种类
- js判断浏览器是pc端还是手机端
- python金融分析小知识(6)——偏度与峰度的计算
- gem install factory_girl
- 深信服应用交付(AD)学习笔记
- 去掉word页眉上横线的技巧
- Shell编程基本指令
- 如何实现windows自带输入法字体任意更改