题目:

A. Fence Planning
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Farmer John’s N cows, conveniently numbered 1…N (2≤N≤105), have a complex social structure revolving around “moo networks” — smaller groups of cows that communicate within their group but not with other groups. Each cow is situated at a distinct (x,y) location on the 2D map of the farm, and we know that M pairs of cows (1≤M<105) moo at each-other. Two cows that moo at each-other belong to the same moo network.

In an effort to update his farm, Farmer John wants to build a rectangular fence, with its edges parallel to the x and y axes. Farmer John wants to make sure that at least one moo network is completely enclosed by the fence (cows on the boundary of the rectangle count as being enclosed). Please help Farmer John determine the smallest possible perimeter of a fence that satisfies this requirement. It is possible for this fence to have zero width or zero height.

Input
The first line of input contains N and M. The next N lines each contain the x and y coordinates of a cow (nonnegative integers of size at most 108). The next M lines each contain two integers a and b describing a moo connection between cows a and b. Every cow has at least one moo connection, and no connection is repeated in the input.

Output
Please print the smallest perimeter of a fence satisfying Farmer John’s requirements.

Example
inputCopy
7 5
0 5
10 5
5 0
5 10
6 7
8 6
8 4
1 2
2 3
3 4
5 6
7 6
outputCopy
10

这个题就是说,给出各个点坐标,和M条点之间路径,求一个能罩住某一个连通块的长方形最小周长。

题意很简单,但是我并查集没有学到位,竟然不是到father函数的路径压缩return fa[a]=father(fa[a]);疯狂tle,打完比赛,一看,被这种路径压缩神仙操作秀到了。

思路就是通过并查集和简单枚举找到每一个连通块的答案,然后输出最小那个就好了。
代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;
//1.06e9大小
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
//鬼畜define
int n,m;
int all[100010][2];
int fa[100010];
typedef struct coor
{int MINX,MAXX,MINY,MAXY;
};
int father(int k)
{if(fa[k]==k)return k;else return fa[k]=father(fa[k]);
}
coor ans[100010];
int main()
{scanf("%d %d",&n,&m);for(int time=0;time<n;time++){fa[time]=time;scanf("%d %d",&all[time][0],&all[time][1]);}for(int time=0;time<m;time++){int from,to;scanf("%d %d",&from,&to);from--;to--;fa[father(from)]=father(to);}for(int time=0;time<n;time++){father(time);}int num=0;for(int time=0;time<n;time++){if(fa[time]==time){ans[time].MINX=INF;ans[time].MAXX=0;ans[time].MINY=INF;ans[time].MAXY=0;}}int C=INF;for(int time=0;time<n;time++){//MINX,MAXX,MINY,MAXYans[father(time)].MINX=min(ans[father(time)].MINX,all[time][0]);ans[father(time)].MAXX=max(ans[father(time)].MAXX,all[time][0]);ans[father(time)].MINY=min(ans[father(time)].MINY,all[time][1]);ans[father(time)].MAXY=max(ans[father(time)].MAXY,all[time][1]);}for(int time=0;time<n;time++){if(fa[time]==time){//printf("%d %d %d %d\n",ans[father(time)].MAXY,ans[father(time)].MINY,ans[father(time)].MAXX,ans[father(time)].MINX);C=min(C,ans[father(time)].MAXY-ans[father(time)].MINY+ans[father(time)].MAXX-ans[father(time)].MINX);}}printf("%d\n",C*2);return 0;
}

GDUT_排位赛题解报告_第2场_Fence Planning相关推荐

  1. GDUT_排位赛题解报告_第3场_B.Loan Repayment

    题目: Farmer John owes Bessie N gallons of milk (1≤N≤1012). He has to give her the milk within K days. ...

  2. GDUT_排位赛题解报告_第5场_A. 唯一排列

    题目 ChenJr给你一个长度为n的排列p,你可以交换其中任意相邻的两个数.现在你需要用最小的交换次数使得这个排列变成升序的序列.现在ChenJr想知道,对于这个排列p,是否存在唯一的交换方式,使得这 ...

  3. GDUT_排位赛题解报告_第5场_C. 积木

    题目: ChenJr已经两个月没有出门了,因此他已经无聊到开始用积木来玩搭房子游戏了. ChenJr首先规定,对于搭建的每一栋房子,他只能选取长度为n的积木作为地基,之后他根据下述的规则进行搭建. 如 ...

  4. 题解报告(CDUT暑期集训——第三场)

    题解报告(CDUT暑期集训--第三场) A - Problem A. Ascending Rating HDU - 6319 思路:单调队列板子题?(但是弱的一批的我还是不会用(有空补上 用的滑动窗口 ...

  5. 题解报告(CDUT暑期集训——第二场)

    题解报告(CDUT暑期集训--第二场) D - Game HDU - 6312 思路:水题 Alice一直是必胜态 AC代码 #include<stdio.h> #include<i ...

  6. 题解报告(CDUT暑期集训——第四场)

    题解报告(CDUT暑期集训--第四场) Problem D. Nothing is Impossible HDU - 6335 思路:水题 排个序循环判断就出来了 AC代码 #include<s ...

  7. 题解报告(CDUT暑期集训——第一场)

    题解报告(CDUT暑期集训--第一场) A - Maximum Multiple HDU - 6298 思路:先按照题意打表 发现规律 就出来了(最开始没开long long贡献了3发 然后又忘了换行 ...

  8. 题解报告(CDUT暑期集训——第六场)

    题解报告(CDUT暑期集训--第六场) A - oval-and-rectangle HDU - 6362 思路:水题 积分一化就出来了 AC代码 #include<stdio.h> #i ...

  9. 题解报告(CDUT暑期集训——第五场)

    题解报告(CDUT暑期集训--第五场) B - Beautiful Now HDU - 6351 思路:直接暴力全排列就行了 最多\(10!\)次 题目限制2500ms 全排列大概是2000多ms(最 ...

最新文章

  1. pytest+allure环境别人电脑运行正常,自己运行不正常几种情况
  2. Maven工程引入jar包(转)
  3. java 银联支付反馈,微信支付/支付宝支付/银联支付,对比加总结(Java服务端)
  4. [论文学习]DIVIDEMIX:带噪声标签的半监督学习LEARNING WITH NOISY LABELS AS SEMI-SUPERVISED LEARNING
  5. QT UI获得控件ID(HWND)
  6. 人人都是 DBA(III)SQL Server 调度器
  7. java同步转化成异步_Java 如何把异步调用模拟成同步调用
  8. AspectCore动态代理中的拦截器详解(一)
  9. 音视频即时通讯二次开发
  10. 首个谷歌TensorFlow安全风险被腾讯找到:攻击成本低、迷惑性强
  11. YV12数据与AVFrame的相互转换
  12. 数据库系统概论第五版_第二章:关系数据库
  13. 最有效的清理C盘/win10如何给系统盘瘦身
  14. border-sizing属性
  15. 奇迹般地修复损坏的Windows、苹果双系统
  16. 计算机 黑屏 显示桌面,电脑开机后显示桌面黑屏了怎么处理啊?
  17. python中path语句什么意思_pythonpythonpath是什么意思?
  18. 微信小程序开发架构——JavaScript的基本概述 和 JavaScript在 Nodejs、小程序中、浏览器中的使用方法
  19. DeepLab语义分割
  20. C语言查找素数的几种实现方法及代码的优化

热门文章

  1. 碰到一个巨坑巨坑的问题,vue设置了baseUrl却不管用?
  2. JavaScript常用表单验证
  3. mysql 查看权限_MySQL查看用户权限
  4. 延迟渲染G-buffer所占显存带宽计算(解决移动端和抗锯齿的若干疑问)
  5. nuxt3 引入高德地图
  6. 【技术贴】MIUI小米桌面图标太乱如何一键刷新桌面排列图标。
  7. ubuntu20.04成功运行PL-VINS
  8. Filter、FilterChain、FilterConfig 介绍
  9. 卜若的代码笔记-一周速通LayaAir-第三章:给Button添加事件
  10. 玩什么别玩优化!WINXP优化精髓!! (很值得学习)