cogs服务点设置(不凶,超乖) x
cogs3. 服务点设置
★ 输入文件:djsa.in 输出文件:djsa.out 简单对比
时间限制:1 s 内存限制:128 MB
为了进一步普及九年义务教育,政府要在某乡镇建立一所希望小学,该乡镇共有n个村庄,村庄间的距离已知,请问学校建在哪个村庄最好?(好坏的标准是学生就近入学,即在来上学的学生中,以最远的学生走的路程为标准。或者说最远的学生与学校的距离尽可能的小。)

0 2 10
0 4 30
0 5 100
1 2 5
2 3 50
3 5 10
4 3 20
4 5 60
要最远的学生与学校的距离尽可能小.
所以 若找到了使得当前枚举的最远的学生与学校距离比以前枚举的更近的话,就进行更新最远距离和学校编号
坑点:
记得每次找最远距离的时候都要清空找到的上一个最远距离(minl)
上代码:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const int Maxint = ;
const int N = ;
int n,m,p,minl=Maxint,maxl=Maxint;
int map[N][N]; int main()
{
freopen("djsa.in","r",stdin);
freopen("djsa.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
map[i][j]=Maxint;
map[i][i]=;
}
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]=w,map[v][u]=w;
}
/*floyd*/
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(map[i][j]>map[i][k]+map[k][j])
map[i][j]=map[i][k]+map[k][j];
for(int i=;i<n;i++)
{
minl=;
for(int k=;k<n;k++)
minl=max(minl,map[i][k]);
if(maxl>minl)
{
maxl=minl;
p=i;
}
}
printf("%d",p);
return ;
}
cogs4. 双服务点设置
☆ 输入文件:djsb.in 输出文件:djsb.out 简单对比
时间限制:1 s 内存限制:128 MB
问题描述
为了进一步普及九年义务教育,政府要在某乡镇建立两所希望小学,该乡镇共有n个村庄,村庄间的距离已知,请问学校建在哪两个村庄最好?(好坏的标准是学生就近入学,即在来上学的学生中,以最远的学生走的路程为标准。或者说最远的学生与学校的距离尽可能的小。)
.gif)
0 2 10
0 4 30
0 5 100
1 2 5
2 3 50
3 5 10
4 3 20
4 5 60
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std; const int Maxint = ;
const int N = ;
int n,m,p1,p2,minl=Maxint,maxl=Maxint;
int map[N][N]; int main()
{
freopen("djsb.in","r",stdin);
freopen("djsb.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
map[i][j]=Maxint;
map[i][i]=;
}
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]=w,map[v][u]=w;
}
/*floyd*/
for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(map[i][j]>map[i][k]+map[k][j])
map[i][j]=map[i][k]+map[k][j];
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
minl=;
for(int k=;k<n;k++)
{
/*
if(i==k || j==k)
continue;
*/
int emmmm=min(map[i][k],map[j][k]);
minl=max(minl,emmmm);
}
if(maxl>minl)
{
maxl=minl;
p1=i,p2=j;
}
}
}
printf("%d %d",p1,p2);
return ;
}
嘻嘻,5还没写啦~
cogs服务点设置(不凶,超乖) x的更多相关文章
- cogs 服务点设置
3. 服务点设置 ☆ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立一所 ...
- COGS 5. P服务点设置
5. P服务点设置 http://www.cogs.pro/cogs/problem/problem.php?pid=5 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对 ...
- cogs 3. 服务点设置 dijkstra
3. 服务点设置 ★ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 为了进一步普及九年义务教育,政府要在某乡镇建 ...
- cogs p服务点设置
5. P服务点设置 ★★ 输入文件:djsc.in 输出文件:djsc.out 简单对比时间限制:2 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立 ...
- cogs 双服务点设置
4. 双服务点设置 ☆ 输入文件:djsb.in 输出文件:djsb.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立两 ...
- dfs -cogs 5 P服务点设置
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=FSXJmiJSg 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立P所希望小学 ...
- 利用efi功能更改bios主板被隐藏的设置(如超频)
整理自(来源): http://tieba.baidu.com/p/4934345324 ([新手教程]利用EFI启动盘修改 隐藏bios设置) http://tieba.baidu.com/p/49 ...
- Charles设置断点- (超详解)
1.选择你要设置断点的接口 2.右键选择 Breakpoints 3.断点的相关配置, Proxy ——>Breakpoint Settings 5.双击刚刚已经设置的断点接口,进行设置 6. ...
- IDEA中设置背景图片(超详细)
文章目录 1.效果图 2.详细设置过程 1.效果图 2.详细设置过程
随机推荐
- http请求之of_ordering_http_post
//Public function of_ordering_http_post (string as_vipsj,string as_url) returns string //string as_v ...
- QObject::connect可以对不继承QObject的类也使用信号槽
#include <QCoreApplication>#include <QDebug>#include <QObject>#include <QThread ...
- HTML——form表单中常用标签 form input (text hidden password radio checkbox reset submit ) select(option)总结
<form action="" method="get"> <!-- placeholder="请输入文本" 显示提示 r ...
- c# TCP/IP协议利用Socket Client通信(只含客户端Demo)
完全是基础,新手可以随意看看,大牛可以关闭浏览页了,哈哈. TCP/IP协议 TCP/IP是一系列网络通信协议的统称,其中最核心的两个协议是TCP和IP.TCP称为传输控制协议,IP称为互联网络协议. ...
- vue-cli3配置eslint
一.默认配置 以下是package.json文件中关于的eslint默认配置 "eslintConfig": { "root": true, "env ...
- redis的数据结构及操作命令
一.字符串: redis中最为基础的存储类型,以二进制存储,value的字符串最多512M,Key做多1024字节. 常用命令:赋值(set).取值(get).删除(del),递增(incr/incr ...
- python与pip
python , pip 相关命令汇总 1) 在python3 下升级pip3 pip3 install --upgrade pip
- php之Opcache
opcache的原理 1.Opcache是什么? Opcache是一种通过将解析的PHP脚本预编译的字节码(Operate Code)存放在共享内存中来避免每次加载和解析PHP脚本的开销,解析器可以直 ...
- 快递100API
url:http://www.kuaidi100.com/query 拼接参数: 参数名称 参数取值 参数类型 type 快递码,请参考快递100码 String postid 快递单号 String ...
- 文本分析:初识Gensim
作者:doze_worm来源:https://www.douban.com/note/620615113/ gensim 起步:本节介绍理解和使用 gensim 所必须的基础概念和术语,并提供一个简单 ...