TOJ1550: Fiber Communications
1550: Fiber Communications 
Total Submit: 3 Accepted:2
Description
Farmer John wants to connect his N (1 <= N <= 1,000) barns (numbered 1..N) with a new fiber-optic network. However, the barns are located in a circle around the edge of a large pond, so he can only connect pairs of adjacent barns. The circular configuration means that barn N is adjacent to barn 1.
FJ doesn't need to connect all the barns, though, since only certain pairs of cows wish to communicate with each other. He wants to construct as few connections as possible while still enabling all of these pairs to communicate through the network. Given the list of barns that wish to communicate with each other, determine the minimum number of lines that must be laid. To communicate from barn 1 to barn 3, lines must be laid from barn 1 to barn 2 and also from barn 2 to barn 3.
Input
* Line 1: Two integers, N and P (the number of communication pairs, 1 <= P <= 10,000)
* Lines 2..P+1: two integers describing a pair of barns between which communication is desired. No pair is duplicated in the list.
Output
One line with a single integer which is the minimum number of direct connections FJ needs to make.
Sample Input
5 2
1 3
4 5
Sample Output
3
Hint
Source
第一次我没看懂题意
n个数排成一个圈,刚开始都没有边相连,你可以给它们之间加上边,但能给相邻的数字之间加边,给出几对要求,要求这几对要求的2个点都必须相连,求最少的需要添加的边数
可能是个二分图?但是一项这个我直接枚举顶多1e7,还是可以跑过去的,枚举开始的点i,然后去连边,居然A掉了
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=;
int l[N],r[N],a[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int ans=n-;
for(int i=;i<=m;i++)
scanf("%d%d",&l[i],&r[i]);
for(int i=;i<n;i++)
{
memset(a,,sizeof(a));
for(int j=;j<=m;j++)
{
int t=(l[j]-i+n-)%n+,w=(r[j]-i+n-)%n+;
if(t>w)swap(t,w);
a[t]++,a[w]--;
}
int k=,w=;
for(int j=;j<n;j++)
{
k+=a[j];
if(k)w++;
}
ans=min(w,ans);
}
printf("%d",ans);
return ;
}
TOJ1550: Fiber Communications的更多相关文章
- [USACO2002][poj1944]Fiber Communications(枚举)
Fiber Communications Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3804 Accepted: 1 ...
- POJ1944 Fiber Communications (USACO 2002 February)
Fiber Communications 总时间限制: 1000ms 内存限制: 65536kB 描述 Farmer John wants to connect his N (1 <= N ...
- POJ 1944:Fiber Communications
Fiber Communications Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4236 Accepted: 1 ...
- POJ 1944 - Fiber Communications
原题地址:http://poj.org/problem?id=1944 题目大意:有n个点排成一圈,可以连接任意两个相邻的点,给出 p 对点,要求这 p 对点必须直接或间接相连,求最少的连接边数 数据 ...
- usaco 2002 月赛 Fiber Communications 题解
Description Farmer John wants to connect his N (1 <= N <= 1,000) barns (numbered 1..N) with a ...
- POJ 1944 Fiber Communications (枚举 + 并查集 OR 线段树)
题意 在一个有N(1 ≤ N ≤ 1,000)个点环形图上有P(1 ≤ P ≤ 10,000)对点需要连接.连接只能连接环上相邻的点.问至少需要连接几条边. 思路 突破点在于最后的结果一定不是一个环! ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- Coroutine in Java - Quasar Fiber实现--转载
转自 https://segmentfault.com/a/1190000006079389?from=groupmessage&isappinstalled=0 简介 说到协程(Corout ...
随机推荐
- WinForm 窗体
Winform是.NET开发中对windows Form的一种称谓,form是窗体的意思,winform 称之为windows form. 一般中我们使用的东西分为 客户端.网页.APP 三大类. w ...
- 洛谷——普及练习场 普及组选手可冲刺训练,提高组选手亦可在此巩固基础。(Loading...)
简单的模拟 关卡2-1,6 道题 开始普及组的训练!所谓模拟,就是直接根据题意编写,思维难度简单. //T1 铺地毯 #include <cstdio> #define N 10005 i ...
- 多目标检测分类 RCNN到Mask R-CNN
最近做目标检测需要用到Mask R-CNN,之前研究过CNN,R-CNN:通过论文的阅读以及下边三篇博客大概弄懂了Mask R-CNN神经网络.想要改进还得努力啊... 目标检测的经典网络结构,顺序大 ...
- ueditor1_3_6 一点问题记录
文件:getRemoteImage.php 第49行: if ( !in_array( $fileType , $config[ 'allowFiles' ] ) || stristr( $heads ...
- [论文理解]SSD:Single Shot MultiBox Detector
SSD:Single Shot MultiBox Detector Intro SSD是一套one-stage算法实现目标检测的框架,速度很快,在当时速度超过了yolo,精度也可以达到two-stag ...
- HTTP、HTTP2.0、HTTPS、SPDY
本文原链接:https://cloud.tencent.com/developer/article/1082516 HTTP,HTTP2.0,SPDY,HTTPS你应该知道的一些事 1.web始祖HT ...
- 2018.4.21 如何正确快速安装/卸载云服务器Centos7安装GUI图形化界面GNOME桌面环境
为云服务哦Centos安装图形化界面GNOME .KDE 1.开始前先验证一下能不能上网 ping www.baidu.com 2.接下来开始安装X(X Window System),命令为 yum ...
- mysql如何让自增id从1开始设置方法
有两种方式 第一种: 如果表中数据没有用.如果直接删除数据,自动增长ID还是不会从1开始的,可以利用“清空数据表”.这样自动增长ID也将会从1开始. 清空表的sql如下 truncate table ...
- new和delete的动态分配。
c++对象模型 视频的实际操作 note: 1.虚函数有虚指针,所以是4,不管有几个虚函数, 都只有一个vptr来存放调用的虚函数的地址. 2.子类的内存是父类内存的加自己的数据内存. 3.clas ...
- CentOS7 安装操作命令
#timedatectl set-timezone Asia/Shanghai 关闭SELinux vi /etc/sysconfig/selinux #SELINUX=enforcing SELIN ...