题意:假设当前有 \(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. MAUI Blazor (Windows) App 动态设置窗口标题

    接着上一篇"如何为面向 Windows 的 MAUI Blazor 应用程序设置窗口标题?" Tips: 总所周知,MAUI 除了 Windows App 其他平台窗口是没有 Ti ...

  2. 【Java Web】项目通用返回模块ServerResponse:枚举code状态码、泛型返回值、序列化注解限制数据

    一.枚举类编写ResponseCode package com.boulderaitech.common; /** * 编写枚举类的步骤 * (1)编写所需的变量 * (2)编写枚举类构造方法 * ( ...

  3. 监控Kubernetes集群证书过期时间的三种方案

    前言 Kubernetes 中大量用到了证书, 比如 ca证书.以及 kubelet.apiserver.proxy.etcd等组件,还有 kubeconfig 文件. 如果证书过期,轻则无法登录 K ...

  4. day36-ThreadLocal

    ThreadLocal 线程数据共享和安全 1.什么是ThreadLocal? ThreadLocal的作用,可以实现在同一个线程数据共享,从而解决多线程数据安全问题 当http请求发送到Tomcat ...

  5. 下载Font Awesome框架

    目录 一:下载Font Awesome框架 二:如何使用font awesome 1.使用图标等样式,点击复制标签即可,需要嵌套在i标签内 2.点击图标,复制标签,然后粘贴使用即可. 3.动态图片等 ...

  6. java时区相关问题(被恶心到了)

    在项目开发中,遇到了mysql5.7数据库相关的时区问题.整理如下: 问题一:在使用swagger测试接口时,数据库记录的时间和输入的不一致.如下图: swagger中输入的是:"recei ...

  7. B站地区限制破解方法

    B站地区限制破解方法 当我们观看bilibili番剧时,经常会看到"仅限港澳台地区"的字样.那么,有没有一种方法,不需要挂梯子,就可以观看这些被限制的番剧呢? 本教程只适用于bil ...

  8. python进阶之路21 正则应用 第三方模块之requests模块 openpyxl模块 简易爬虫(pandas)

    作业讲解 """ 网络爬虫没有我们现在接触的那么简单 有时候页面数据无法直接拷贝获取 有时候页面还存在防爬机制 弄不好ip会被短暂拉黑 """ ...

  9. python进阶之路2——解释器软件安装

    内容概要 计算机五大组成部分 计算机三大核心硬件 操作系统 编程与编程语言 编程语言发展史 编程语言的分类 python解释器下载与安装 python解释器多版本共存 pycharm安装 计算机五大组 ...

  10. 普冉PY32系列(二) Ubuntu GCC Toolchain和VSCode开发环境

    目录 普冉PY32系列(一) PY32F0系列32位Cortex M0+ MCU简介 普冉PY32系列(二) Ubuntu GCC Toolchain和VSCode开发环境 以下介绍PY32F0系列在 ...