当前位置: 首页 > news >正文

网站建设类公司可以拿哪些项目资金服装定制公司

网站建设类公司可以拿哪些项目资金,服装定制公司,网站栏目功能分析,免费代理浏览器在线P2847 [USACO16DEC] Moocast G [USACO16DEC] Moocast G 题面翻译 Farmer John 的 N N N 头牛 ( 1 ≤ N ≤ 1000 1 \leq N \leq 1000 1≤N≤1000) 为了在他们之间传播信息,想要组织一个"哞哞广播"系统。奶牛们决定去用步话机装备自己而不是在很远的距离…

P2847 [USACO16DEC] Moocast G

[USACO16DEC] Moocast G

题面翻译

Farmer John 的 N N N 头牛 ( 1 ≤ N ≤ 1000 1 \leq N \leq 1000 1N1000) 为了在他们之间传播信息,想要组织一个"哞哞广播"系统。奶牛们决定去用步话机装备自己而不是在很远的距离之外互相哞哞叫,所以每一头奶牛都必须有一个步话机。这些步话机都有一个限制传播半径,但是奶牛们可以间接地通过中间奶牛传播信息,所以并不是每头牛都必须直接向其他每一头奶牛连边。

奶牛们需要去决定多少钱花在步话机上,如果他们花了 X X X, 那么他们都将会得到 X \sqrt{X} X 距离的步话机。所以,两头牛之间的欧几里得距离平方最多是 X X X。请帮助奶牛们找到最小的 X X X 使得图是强连通的。

题目描述

Farmer John’s N N N cows ( 1 ≤ N ≤ 1000 1 \leq N \leq 1000 1N1000) want to organize an emergency “moo-cast” system for broadcasting important messages among themselves.

Instead of mooing at each-other over long distances, the cows decide to equip themselves with walkie-talkies, one for each cow. These walkie-talkies each have a limited transmission radius, but cows can relay messages to one-another along a path consisting of several hops, so it is not necessary for every cow to be able to transmit directly to every other cow.

The cows need to decide how much money to spend on their walkie-talkies. If they spend X X X, they will each get a walkie-talkie capable of transmitting up to a distance of X \sqrt{X} X . That is, the squared distance between two cows must be at most X X X for them to be able to communicate.

Please help the cows determine the minimum integer value of X X X such that a broadcast from any cow will ultimately be able to reach every other cow.

输入格式

The first line of input contains N N N.

The next N N N lines each contain the x x x and y y y coordinates of a single cow. These are both integers in the range 0 … 25 , 000 0 \ldots 25,000 025,000.

输出格式

Write a single line of output containing the integer X X X giving the minimum amount the cows must spend on walkie-talkies.

样例 #1

样例输入 #1

4
1 3
5 4
7 2
6 1

样例输出 #1

17

提示

没有提示

题解

根本用不着二分答案嘛。直接 N 2 N^2 N2建边,跑一遍Kruskal。记录在最小生成树中的最长的一条边。显然只要使得这条边能够建立,那么这棵最小生成树中的所有的边都可以建立。答案就是最长的边的距离的平方,注意要用 d o u b l e double double存边权。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>using namespace std;const int maxn = 1e3+3;
int n, x[maxn], y[maxn], cnt, tot, f[maxn];
double Ans;
struct Edge{int u, v;double w;
}ed[maxn * maxn];
inline bool cmp(Edge a, Edge b){return a.w < b.w;
}
inline int find(int x){if(x == f[x]) return x;else return f[x] = find(f[x]);
}
inline void Kruskal(){for(int i=1; i<=n; i++) f[i] = i;for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){if(i != j){++cnt;ed[cnt].u = i, ed[cnt].v = j, ed[cnt].w = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));}}}sort(ed+1, ed+1+cnt, cmp);for(int i=1; i<=cnt; i++){int xx = find(ed[i].u), yy = find(ed[i].v);if(xx != yy){f[xx] = find(yy);tot ++;Ans = ed[i].w;}if(tot == n-1){break;}}
}int main(int argc, const char * argv[]){scanf("%d", &n);for(int i=1; i<=n; i++){scanf("%d%d", &x[i], &y[i]);}Kruskal();printf("%.0lf", Ans * Ans);
}
//Written by Kevin ☑

当然,最小生成树才是这道题的最优解

为什么呢?大家应该都学过勾股定理吧?在平面直角坐标系中,两点A(x1,y1),B(x2,y2)的距离|AB|等于 s q r t ( ( x 1 − x 2 ) 2 + ( y 1 − y 2 ) 2 sqrt((x1-x2)^2+(y1-y2)^2 sqrt((x1x2)2+(y1y2)2,而我们可以发现,我们最后要求的是最大的 ∣ A B ∣ 2 |AB|^2 AB2,也就是 ( x 1 − x 2 ) 2 + ( y 1 − y 2 ) 2 (x1-x2)^2+(y1-y2)^2 (x1x2)2+(y1y2)2(当然在C++里得写成(x1-x2) * (x1-x2)+(y1-y2) * (y1-y2)),所以,我们只要求出边权为两点距离平方的最小生成树中最长边的长就可以了。

首先,我们可以通过一次双重循环求出每条边的边权,然后再跑一边最小生成树算法。

被熟知的求最小生成树的算法有prime、kruskal两种,而这次我们的图是完全图(即图的每两点之间都有连边),而prime更适合跑稠密图,因此我们选用prime算法。

#include<bits/stdc++.h>
using namespace std;
long long n,i,j,x[1001],y[1001],p[1001][1001],d[1001],u,max1;
bool b[1001];
priority_queue<pair<long long,long long> >q;//堆优化
int main(int argc, const char * argv[]){scanf("%lld",&n);for (i=1;i<=n;i++)scanf("%lld%lld",&x[i],&y[i]);for (i=1;i<=n;i++)for (j=1;j<=n;j++)p[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);//求出两两点之间的距离for (i=1;i<=n;i++) d[i]=1e11;d[1]=0;max1=0;q.push(make_pair(0,1));while (q.size()){u=q.top().second;q.pop();if (b[u]) continue;max1=max(max1,d[u]);//求出最大边权b[u]=true;for (i=1;i<=n;i++)if (d[i]>p[u][i]){d[i]=p[u][i];q.push(make_pair(-d[i],i));//prime}}printf("%lld",max1);return 0;
}
//Written by Kevin ☑︎
http://www.yayakq.cn/news/738468/

相关文章:

  • 龙岗区网站建设哪个公司好专业竞价托管哪家好
  • 吉安好的网站建设公司网站设计公司皆选奇点网络
  • 官方制作网站网站如何建设成直播间
  • 怎样制作网站建设规划图企业品牌推广公司哪家好
  • 甘肃建设职工教育培训中心网站计算机网站建设招聘
  • 网站服务器买了后怎么做网络营销招聘岗位有哪些
  • 广西自治区集约化网站建设要求互联网开发是做什么的
  • 做暧暧网站免费网站建设招聘条件
  • 去了哪找网站建设公司建站行业市场分析
  • 怎样做集装箱网站做网站需要买什么东西
  • 石家庄企业商城版网站建设wordpress评分点评
  • 物流网站 源码wordpress购物车保存
  • 深圳企业模板建站wordpress模板 科技
  • 猪八戒网网站开发需求网站建设基本模板介绍
  • 推广网站的几种方法怎样设计一个网站
  • 网站ip地址查询搭建农村电商平台
  • 深圳排名网站小白怎么做跨境电商
  • 住建部网站2015年城市建设统计观澜做网站公司
  • 单位网站设计制作唐山网站建设唐山做网站
  • 中国建设银行陕西分行官方网站c2c模式类型
  • 局域网站建设装修公司加盟品牌
  • 企业网站建设专家开公司要多少注册资金
  • 淘宝做网站为什么那么便宜中英文网站英文
  • 深圳建设培训中心网站免费响应式模板网站模板下载
  • 南昌的网站推广公司线上营销推广方式
  • 深圳网站建设空间wordpress 排除指定分类
  • 个人如何建设网站wordpress微信分享代码
  • 大家都在哪些网站做宣传惠山网页制作
  • 在线销售网站设计文献iis里如何装php网站
  • 网站开发运营推广叫什么佳木斯市城乡建设局网站