HDU 6090 Rikka with Graph
来源:互联网 发布:windows server 2012 编辑:程序博客网 时间:2024/05/28 16:15
题目地址
题意:给你n个点和m条边,让你去尽可能的连点,如果是两点之间不能到达,他们的距离就是n,反之则为距离为连的长度
思路:先所有的边都用去连1,这样的话就是连n-1条边(得到的情况就是与1相连的点距离为1,其他为2),所以判断一下能不能有n-1条边,如果有的话剩余的边就连非1的点,这样的话和就是减少2的代价,然后这样求就好了(看代码)
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 10010#define LL __int64#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1e9 + 7;const double eps = 1e-9;const int inf = 1 << 28;LL getx(LL x){ LL p = x - 1; return p * 2 + p*(p - 1) * 2;}int main() { cin.sync_with_stdio(false); int T; LL n, m; LL ans; cin >> T; while (T--) { cin >> n >> m; m = min(n*(n - 1) / 2, m); if (m < n - 1) { ans = getx(m + 1);//有m+1个点相连的代价 LL p = n - (m + 1);//还有多少点没有连 ans += (m + 1) * p * n * 2; ans += p*(p - 1)*n; } else { m -= (n - 1); ans = getx(n); ans -= m * 2; } cout << ans << endl; } return 0;}
阅读全文
0 0
- HDU 6090 Rikka with Graph
- HDU 6090 Rikka with Graph
- [HDU 6090]Rikka with Graph
- hdu 6090 Rikka with Graph
- HDU 6090 Rikka with Graph
- HDU 6090 Rikka with Graph
- hdu 6090-Rikka with Graph
- hdu--6090--Rikka with Graph
- [HDU 6090]Rikka with Graph
- hdu 6090-Rikka with Graph
- HDU 6090-Rikka with Graph
- HDU 6090 Rikka with Graph
- Rikka with Graph HDU
- Hdu 6090 Rikka with Graph【贪心】
- hdu 6090 Rikka with Graph [想法题]
- HDU 6090 Rikka with Graph(规律)
- HDU 6090 Rikka with Graph(思维)
- HDU 6090 Rikka with Graph【规律】
- Rigidbody.AddForce
- 跨域解决方案 & 使用angularJS和jQuery进行Ajax请求的差异
- 组群管理
- SDWebImage的源码解读
- DataTable其它细节
- HDU 6090 Rikka with Graph
- 0808 Java面向对象特征之封装
- linux文件系统介绍
- 文件权限管理
- SVN服务器端和客户端的搭建和使用
- localStorage存储数组以及取数组方法
- Python-WXPY实现微信监控报警
- html+css+javascript代码编程规范之JavaScript
- apache hadoop 2.6.4 64bit 在windows8.1下直接安装指南(无需虚拟机和cygwin)