CF818F - Level Generation
题意:假设当前有 \(n\) 个点,求最多的边数,使得桥的数量 \(\ge\lceil\dfrac{m}{2}\rceil\)。
我们考虑构造,首先,整张图一共只有一个双连通分量。因为我们如果有两个双连通分量,完全可以通过同构结合成一个。而从双连通分量之外的所有边都是桥,不妨假设它就是一条链。那么,链上有 \(n-x\) 条边,右边的 \(x\) 个点之间的所有边不是桥,最多有 \(x(x-1)/2\) 条。又因为桥的数量必须在两倍以上,最多有 \(n-x\) 条边。
所以选 \(x\) 个点的最优边数就是 \(n-i+\min(n-i,i(i-1)/2)\),也就是 \(\min(2n-2i,n-i+i(i-1)/2)\)。
我们发现这两个部分左边单调减,右边单调增(\(i^2\) 增长率在 \(i\ge 1\) 的情况下大于 \(n-i\)),那么最大值一定出现在两边相等的时候。
解方程 \(n-i=i(i-1)/2\)
\]
\]
\]
\]
\]
\]
所以我们找到了最大值出现的位置。但是因为整数计算过程中的误差,真正的解也可能是 \(x+1\),都计算出来找最小值即可。
复杂度取决于 'sqrt' 的实现,如果是二分法则为 \(O(\log n)\),如果是牛顿迭代(不知道是什么,但是网上说有),复杂度就是 \(O(1)\) 的
int n;
inline void solve(){
cin>>n;
ll ans=0,d=1+8*(ll)n;
d=(-1+sqrt(d))/2;
for(int i=max(1ll,d);i<=min((ll)n,d+1);i++){
ans=max(ans,n-i+min((ll)n-i,1ll*i*(i-1)/2));
}cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
rd(_,t)solve();
return 0;
}
//Crayan_r
CF818F - Level Generation的更多相关文章
- iPhone Tutorials
http://www.raywenderlich.com/tutorials This site contains a ton of fun written tutorials – so many t ...
- Educational Codeforces Round 24 CF 818 A-G 补题
6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 1094. The Largest Generation (25)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- PAT1094:The Largest Generation
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT A1094 The Largest Generation (25 分)——树的bfs遍历
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- A1094. The Largest Generation
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- PAT 甲级 1094 The Largest Generation
https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...
随机推荐
- 【SQL基础】基础查询:所有列、指定列、去重、限制行数、改名
〇.建表数据 drop table if exists user_profile; CREATE TABLE `user_profile` ( `id` int NOT NULL, `device_i ...
- Java基础知识篇【gitee】
https://snailclimb.gitee.io/javaguide 一.Java基本功 Java一次编译,字节码通过JVM,处处运行jsp会转化为servlet,也要由jdk编译OracleJ ...
- CountDownLatch闭锁源码解析(基于jdk11)
目录 CountDownLatch闭锁源码解析(基于jdk11) 1.1 CountDownLatch概述 1.2 CountDownLatch原理 1.2.1 基本结构(jdk11) 1.2.2 a ...
- PL/SQL Developer使用中文条件查询时无数据的解决方法
1.在PL/SQL Developer中执行sql命令:select userenv('language') from dual; 显示结果为:AMERICAN_AMERICA.ZHS16GBK: 2 ...
- 中国风?古典系?AI中文绘图创作尝鲜!⛵
作者:韩信子@ShowMeAI 深度学习实战系列:https://www.showmeai.tech/tutorials/42 本文地址:https://www.showmeai.tech/artic ...
- python 之选择结构(if --elif --else)
python中有三种结构:顺序结构.选择结构.循环结构,此处介绍选择结构. if -- else 结构: if 判断条件: 执行语句 else: 执行语句 当if后面的判断条件为真(True)时,执行 ...
- sha1_b64_scrape
过无限debugger:https://www.cnblogs.com/hkwJsxl/p/16702143.html 网站 aHR0cHM6Ly9hbnRpc3BpZGVyOC5zY3JhcGUuY ...
- JUC源码学习笔记7——FutureTask源码解析,人生亦如是,run起来才有结果
系列文章目录和关于我 一丶我们在哪里会使用到FutureTask 基本上工作中和Future接口 打交道比较多,比如线程池ThreadPoolExecutor#sumbit方法,返回值就是一个Futu ...
- [编程基础] Python谷歌翻译库googletrans总结
1 使用说明 本文介绍python谷歌翻译库接口googletrans的使用.具体见官方文档: https://py-googletrans.readthedocs.io/en/latest/#goo ...
- [R语言] WGCNA入门教程
文章目录 wgcna入门-雌性小鼠肝脏表达数据的网络分析:寻找与体重有关的模块 1 数据输入和清洗 1.1 加载基因表达数据 1.2 数据清洗 1.3 加载临床特征数据 2 建设表达网络与模块检测 2 ...