题解:考虑贪心地一条一条边添加进去。

当 m \leq n-1m≤n−1 时,我们需要最小化距离为 nn 的点对数,所以肯定是连出一个大小为 m+1m+1 的联通块,剩下的点都是孤立点。在这个联通块中,为了最小化内部的距离和,肯定是连成一个菊花的形状,即一个点和剩下所有点直接相邻。

当 m > n-1m>n−1 时,肯定先用最开始 n-1n−1 条边连成一个菊花,这时任意两点之间距离的最大值是 22。因此剩下的每一条边唯一的作用就是将一对点的距离缩减为 11。

这样我们就能知道了最终图的形状了,稍加计算就能得到答案。要注意 mm 有可能大于 \frac{n(n-1)}{2}​2​​n(n−1)​​。

队友给力,手速快,赛后补代码都补了20多分钟,,, 果然自己代码实现能力还是弱渣。

AC代码:

#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
using namespace std;
typedef long long ll;
ll get(ll n)
{
ll temp=n-1ll;
temp+=(n-1ll)*((2ll)*n-3ll);
return temp;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,m;
scanf("%lld %lld",&n,&m);
ll ans=;
m=min(m,(n-1ll)*n/2ll);
if(m <= n-)
{
ans+=get(m+);
ll temp=n-m-;
ans+=temp*(m+)*n*;
ans+=(temp-1ll)*temp*n;
cout<<ans<<endl;
}
else
{
ll temp=get(n)-(m-(n-))*;
cout<<temp<<endl;
}
}
return ;
}

Rikka with Graph hdu 6090的更多相关文章

  1. B - Rikka with Graph HDU - 5631 (并查集+思维)

    As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...

  2. HDU 6090 Rikka with Graph

    Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  3. 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) ...

  4. HDU 5631 Rikka with Graph 暴力 并查集

    Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...

  5. HDU 5422 Rikka with Graph

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. HDU 5424——Rikka with Graph II——————【哈密顿路径】

    Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. Rikka with Graph(联通图取边,暴力)

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. Rikka with Graph(hdu5631)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  9. HDU 6090 17多校5 Rikka with Graph(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

随机推荐

  1. 在testrpc以太坊测试环境部署智能合约

    2018年03月13日 09:20:54 思无邪-machengyu 阅读数 2683   版权声明:本文为博主原创文章,转载请务必注明出处,否则追究法律责任 https://blog.csdn.ne ...

  2. Mapping Pocos

    Mapping Pocos Example Pocos/Mappings public class Note { public int Id { get; set; } public DateTime ...

  3. PHP学习之工厂方法模式

    <?php //工厂方法模式 interface Doing { function eat(); function sleep(); } class Cat implements Doing { ...

  4. linux下如何批量替换多个文件中的某个字符串?

    答: sed -i "s/<old_string>/<new_string>/g" `grep "<old_string>" ...

  5. SQL-W3School-高级:SQL ALTER TABLE 语句

    ylbtech-SQL-W3School-高级:SQL ALTER TABLE 语句 1.返回顶部 1. ALTER TABLE 语句 ALTER TABLE 语句用于在已有的表中添加.修改或删除列. ...

  6. 如何在CentOS 7上安装Memcached(缓存服务器)

    首先更新本地软件包索引,然后使用以下yum命令从官方CentOS存储库安装Memcached. yum update yum install memcached 接下来,我们将安装libmemcach ...

  7. 将ByteBuffer保存成文件

    String dest = "d:/download/" + name; Path path = Paths.get(dest).getParent().toAbsolutePat ...

  8. 从字节跳动离职后,拿到探探、趣头条、爱奇艺、小红书、15家公司的 offer【转】

    前言 博主目前从事Android开发3年,前两年一直在抖音工作.我这篇文章并不是简单的描述一些面试中的题,或者总结一些Android的知识,而是想记录我整个的想法和准备的过程,以及一些心得体会,让大家 ...

  9. C#使用MPI进行高性能计算

    MPI.NET是用于Microsoft.NET环境的高性能.易于使用的消息传递接口(MPI)实现.mpi是编写在分布式内存系统(如计算集群)上运行的并行程序的事实上的标准,并且得到了广泛的实现.大多数 ...

  10. Course1_Week1_ProgrammingHomeWork

    Exercise 1: Pascal's Triangle The following pattern of numbers is called Pascal's triangle. 1 1 1 1 ...