题意:假设当前有 \(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\)

\[2n=i(i+1)
\]
\[i^2+i-2n=0
\]
\[\Delta=1^2-4(-2n)=1+8n
\]
\[x_1=\dfrac{-1+\sqrt{\Delta}}{2},x_2=\dfrac{-1-\sqrt{\Delta}}{2}
\]
\[\because x>0
\]
\[\therefore x=\dfrac{-1+\sqrt{1+8n}}{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的更多相关文章

  1. iPhone Tutorials

    http://www.raywenderlich.com/tutorials This site contains a ton of fun written tutorials – so many t ...

  2. Educational Codeforces Round 24 CF 818 A-G 补题

    6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...

  3. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  4. 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 ...

  5. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  6. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  7. PAT1094:The Largest Generation

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  8. 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 ...

  9. A1094. The Largest Generation

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  10. PAT 甲级 1094 The Largest Generation

    https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...

随机推荐

  1. 环境安装-Centos7.4安装及配置

    环境安装-Centos7.4安装及配置 〇.资料汇总 一.虚拟机安装 1.下载地址 https://pan.baidu.com/s/1zcOp06HX4OxPdsCCGkHbXQ 提取码:7777 2 ...

  2. 【HarmonyOS】ArkTS Native开发——使用 system函数创建文件

    ​ ArkTS是HamronyOS优选的主力语言,但官方文档指南中对于Native应用开发并没有详细的描述,只有一篇Codelab可以学习(简易Native C++ 示例(ArkTS) (huawei ...

  3. UBOOT 启动流程

    一.概述 uboot 的启动流程在网上有很多大佬记录,但是了对于像我这样的新手就有些困难了,而我也不做 uboot 相关的工作,所以没必去研究代码,这里我特意整理了一下,以流程图的形式展现代码执行的流 ...

  4. 【FAQ】在华为鸿蒙车机上集成华为帐号的常见问题总结

    随着新一代信息技术与汽车产业的深度融合,智能网联汽车正逐渐成为汽车产业发展的战略制高点,无论是传统车企还是新势力都瞄准了"智能座舱"这种新一代人机交互方式.面对竞争如此激烈的车机市 ...

  5. Sql Server中order by对varchar类型排序结果不对

    1.问题描述 我写一个sql想要把查询结果根据LineNumber升序进行排序,即1.0,1.1,1.2,...1.3.2....2.0,......10.0,......15.2,......这样子 ...

  6. C语言指针常见问题

    我们在学C语言时,指针是我们最头疼的问题之一,针对C语言指针,博主根据自己的实际学到的知识以及开发经验,总结了以下使用C语言指针时常见问题. 指针 指针做函数参数 学习函数的时候,讲了函数的参数都是值 ...

  7. Spring Boot通过Actuator显示git和build的信息

    1 简介 为了更好的版本控制和问题定位,我们需要知道正在运行的应用是什么版本,什么时候打包的,Git的相关信息等.通过/actuator/info可以帮助我们获取这些信息. 2 配置 首先要有actu ...

  8. 浅谈RMQ问题

    RMQ:question 有一个长度为 N N N的数组,数组中的数是无序的( 1 < = n < = 5 ∗ 1 0 5 1<=n<=5*10^5 1<=n<=5 ...

  9. 如何解决github下载很慢的问题?(已经解决)

    目的是为了解决GitHub致命的下载速度慢的问题 方法 通过码云来导入github,通过码云下载 1.在github上面找到自己想要的项目 这一步略过 2.复制github项目上面的网页链接 3.打开 ...

  10. 前端基础知识-css(一)个人学习记录

    待补充 flex及其属性 https://blog.csdn.net/weixin_44706267/article/details/121291934 css3新特性 sass和less https ...