Codeforces 818F Level Generation(三分)
来源:互联网 发布:java99乘法表数组编程 编辑:程序博客网 时间:2024/05/24 03:19
F. Level Generation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be exactly ni vertices in the graph representing level i, and the edges have to be bidirectional. When constructing the graph, Ivan is interested in special edges called bridges. An edge between two vertices u and v is called a bridge if this edge belongs to every path between u and v (and these vertices will belong to different connected components if we delete this edge). For each level Ivan wants to construct a graph where at least half of the edges are bridges. He also wants to maximize the number of edges in each constructed graph.
So the task Ivan gave you is: given q numbers n1, n2, …, nq, for each i tell the maximum number of edges in a graph with ni vertices, if at least half of the edges are bridges. Note that the graphs cannot contain multiple edges or self-loops.
Input
The first line of input file contains a positive integer q (1 ≤ q ≤ 100 000) — the number of graphs Ivan needs to construct.
Then q lines follow, i-th line contains one positive integer ni (1 ≤ ni ≤ 2·109) — the number of vertices in i-th graph.
Note that in hacks you have to use q = 1.
Output
Output q numbers, i-th of them must be equal to the maximum number of edges in i-th graph.
Example
input
3
3
4
6
output
2
3
6
Note
In the first example it is possible to construct these graphs:
1 - 2, 1 - 3;
1 - 2, 1 - 3, 2 - 4;
1 - 2, 1 - 3, 2 - 3, 1 - 4, 2 - 5, 3 - 6.
题目大意:
告诉你结点数,让你构造一张图,其中桥至少要占边数的一半,问最多能够有多少条边。
解题思路:
我们可以先取
AC代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <stack>#include <map>using namespace std;#define INF 0x3f3f3f3f#define LL long long#define fi first#define se second#define mem(a,b) memset((a),(b),sizeof(a))#define sqr(x) ((x)*(x))LL N;inline LL judge(const LL &x){ return min(N-x, x*(x-1)/2)+N-x;}int main(){ int T_T; scanf("%d", &T_T); while(T_T--) { scanf("%lld", &N); LL l=1, r=N; while(r-l>2) { LL mid=(l+r)/2; LL midmid=(mid+r)/2; if(judge(midmid)>judge(mid)) l=mid; else r=midmid; } printf("%lld\n", max(judge(l), max(judge(l+1), judge(r)))); } return 0;}
- Codeforces 818F Level Generation(三分)
- codeforces818F Level Generation -- 三分
- codeforces 773F. Test Data Generation
- ICPCCamp2017 Day 4 F Factory(三分套三分)
- GYM 100971 F.Two Points(三分)
- CodeForces 626E Simple Skewness(三分)
- Codeforces 626E Simple Skewness(三分)
- Codeforces 234F (dp)
- codeforces 731F (暴力)
- codeforces 732F (桥)
- Codeforces 659F F
- Codeforces #427 E题Police Patrol(三分查找)
- Codeforces Round #344 (Div. 2) E. Product Sum (三分)
- CodeForces 605 C.Freelancer's Dreams(三分)
- Codeforces Round #403 (Div. 2) B 二分 or 三分
- Codeforces Gym 100825 B. Delete This! (枚举 + 三分)
- Codeforces 626E. Simple Skewness(三分)详细注释
- CodeForces 589F -- F. Gourmet and Banquet (二分 + 贪心)
- 【2017今日头条】头条校招
- js回车事件
- 四大线程池详解
- 读取文本文件的所有行并写入到数据库
- python 高阶函数:sort,filter,reduce,map
- Codeforces 818F Level Generation(三分)
- yii2 常用组件 -- 折叠主键(Collapse)
- JS笔记 —— 回调函数
- 【学习摘记】马士兵HTML & CSS_课时2_链接到页面的某个具体位置、背景图片与引用路径
- git、svn版本管理规范
- 常用的图片加载库的使用和对比Fresco、Glide、Picasso、Image-loader
- [笔记]《操作系统精髓与设计原理》---(4)并发
- 30岁程序员困境:转行or跳槽?如何做才不会被替代?
- C++学习笔记(一)