【构造】【贪心】hdu6090 Rikka with Graph
给你n个点,让你连m条边,使得任意两两点对之间的最短路的和最小(两点若不可达,最短路记作n)。
初始时ans=n*n*(n-1)。
先尽量连成菊花图,每连一次让答案减小2*((n-2)*(i-1)+(n-1)),i为当前菊花图中的点数。
连完后剩下的边,每连一次让答案减小2。
如果已经用了n*(n-1)/2条边,剩下的边没有意义。
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans,m;
int T,n;
int main(){
scanf("%d",&T);
for(;T;--T){
scanf("%d%lld",&n,&m);
ans=(ll)n*(ll)(n-1)*(ll)n;
if(m<(ll)n){
for(int i=1;i<=(int)m;++i){
ans-=(ll)(i-1)*(ll)(n-2)*2ll;
ans-=(ll)(n-1)*2ll;
}
}
else{
for(int i=1;i<n;++i){
ans-=(ll)(i-1)*(ll)(n-2)*2ll;
ans-=(ll)(n-1)*2ll;
}
ll lim=min((ll)n*(ll)(n-1)/2ll,m);
ans-=(lim-(ll)n+1ll)*2ll;
}
printf("%lld\n",ans);
}
return 0;
}
【构造】【贪心】hdu6090 Rikka with Graph的更多相关文章
- HDU 6090 Rikka with Graph —— 2017 Multi-University Training 5
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5422 Rikka with Graph
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Rikka with Graph(联通图取边,暴力)
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 6090 Rikka with Graph
Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- HDU 5631 Rikka with Graph 暴力 并查集
Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...
- HDU 5424——Rikka with Graph II——————【哈密顿路径】
Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Rikka with Graph(hdu5631)
Rikka with Graph Accepts: 123 Submissions: 525 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- ACM学习历程—HDU5422 Rikka with Graph(贪心)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- hdu 5424 Rikka with Graph II(dfs+哈密顿路径)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so h ...
随机推荐
- Eureka Server的高可用
Eureka Server进行互相注册的方式来实现高可用的部署,所以我们只需要将Eureke Server配置其他可用的serviceUrl就能实现高可用部署 创建application-peer1. ...
- Msfvenom学习总结-MSF反弹webshell
1. –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...
- ASPxTreeList的右键按钮事件
ASPxTreeList应该是比较长用的控件了~现在就来说说它的右键按钮事件 这里实现的是右键里有折合和展开所有节点的功能 code: <dx:ASPxTreeList ID="ASP ...
- vue 开始开发
1,引入vue.js文件 2,在body里用标签 编辑一个入口 <div id="app">{{msg}}</div> <-- 用双大括号 取数据显示 ...
- Assistor PS 切图工具的使用说明。
一.如何运行Assistor PS 使用这个Assistor PS 软件有一个最最重要的条件,那就是:你要打开你的Photoshop (官方建议版本在CS 3以上) 下载-安装-运行. 运行成 ...
- 设置Eclipse/MyEclipse中编辑界面点击任何文件后Package Explorer导航自动定位该文件
原文:http://www.myexception.cn/eclipse/425836.html 设置步骤: 导航Package Explorer的右上角有一个黄色双向箭头图标,鼠标移动到上面提示“L ...
- Intellij idea的maven依赖图
Intellij idea下查看maven的依赖图与eclipse有所不同.下面简单介绍一下Intellij下maven的查看使用. 使用场景 当你想查看maven依赖的jar都有哪些,是否有冲突,冲 ...
- Django-form組件補充
自定义验证规则 方法一: 1 2 3 4 5 6 7 8 9 10 from django.forms import Form from django.forms import widgets f ...
- react表单提交
class FlavorForm extends React.Component { constructor(props) { super(props); this.state = {value: ' ...
- memcached安装+绑定访问ip
安装: 1.由于memcached是基于libevent的,需要安装libevent,libevent-devel $yum -y install libevent libevent-devel 2. ...