题意:假设当前有 \(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. 【极客时间】大数据概述及HDFS介绍

  2. USB限流IC,限流开关保护芯片

    PW1503和PW1502是超低RDS(ON)开关,具有可编程电流限制的USB限流IC,以保护电源于过电流负载和正极负极短路的保护.它具有过温保护以及反向闭锁功能. PW1503,PW1502均采用S ...

  3. 简单的Dos命令学习

    Dos命令学习 打开CMD的方式 从菜单栏打开,windows系统里 win+R 输入cmd 在任意文件夹下,按住shift+右键,点击打开PowerShell 在资源管理器的地址栏前面加上cmd+空 ...

  4. HDOJFatmouse肥鼠交易//c++控制保留小数

    贪心算法.我就不贴题了//no.1009 但是我的代码运行超时了-改了好久都不对- 看别人代码,顺便学习c++控制保留小数怎么操作; 我的错误代码:(时间占用可能是多次调用findmax造成的) #i ...

  5. 网络基础与osi七层与TCP/IP协议

     一 什么是网络 网络:计算机网络是一组计算机或网络设备通过有形 的线缆或无形的媒介如无线,连接起来,按照一定的 规则,进行通信的集合. 通信,是指人与人.人与物.物与物之间通过某种媒 介和行为进行的 ...

  6. 过滤器 Filter 与 拦截器 Interceptor 的区别

    引言 说起 Filter 与 Interceptor 的区别,相信很多同学第一感觉就是容易.简单! 毕竟开发中这两个组件使用频率较高,用法也较简单.然后真回答起来有答不出个所以然来,场面尴尬,老丢脸了 ...

  7. MongoDB - 模式设计

    注意事项 模式设计,即在文档中表示数据的方式,对于数据表示来说时非常关键的. 为 MongoDB 做模式设计时,在性能.可伸缩性和简单性方面是重中之重,也需要考虑一些特别的注意事项. 限制条件 与常见 ...

  8. [数据与分析可视化] D3入门教程2-在d3中构建形状

    d3.js入门教程2-在 d3.js中构建形状 文章目录 d3.js入门教程2-在 d3.js中构建形状 形状的添加 圆形的添加 矩形的添加 线段的添加 文本的添加 折线的添加 区域的添加 圆弧的添加 ...

  9. Nodejs报错记录

    ◉ digital envelope routines::unsupported D:\workspace\vuedemo> npm run dev ... error:0308010C:dig ...

  10. 软件安装——idea的安装和使用

    Idea的安装和使用 一.下载和安装 下载步骤 官网下载地址:Download IntelliJ IDEA: The Capable & Ergonomic Java IDE by JetBr ...