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 ...
随机推荐
- 【每日一题】【栈】2022年2月2日-NC40 两个链表生成相加链表
描述 假设链表中每一个节点的值都在 0 - 9 之间,那么链表整体就可以代表一个整数. 给定两个这种链表,请生成代表两个整数相加值的结果链表. 答案:栈 import java.util.*; /* ...
- 简易博客页面小项目 html css
项目预览 代码 html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- 使用echarts(可视化图表库)
一:echarts 1.简介 一个基于 JavaScript 的开源可视化图表库 echarts官网使用教程: https://echarts.apache.org/zh/index.html 2.e ...
- 无人机集群的分布式协作 VI-SLAM
以下内容来自从零开始机器人SLAM知识星球 每日更新内容 点击领取学习资料 → 机器人SLAM学习资料大礼包 论文# D2SLAM: Decentralized and Distributed Col ...
- A_A01_001 KEIL4-KEIL5软件安装
@ 目录 一.软件下载 二.交流学习 三.防止电脑误删文件操作步骤 四.KEIL4安装 五.KEIL5安装 六.注意事项 一.软件下载 KEIL4/KEIL5网盘链接 戳它跳转 提取码:omni 二. ...
- django.db.migrations.exceptions.NodeNotFoundError: Migration apitest.0001_initial dependencies reference nonexistent parent node ('product', '0001_initial')
执行python manage.py makemigrations时出现以下错误 D:\autotestplat>python manage.py makemigrations Tracebac ...
- input限制只能输入汉字
<el-form class="det_foot" :model="form" :rules="rules" ref="fo ...
- Python实验报告(第8章)
实验8:模块 一.实验目的和要求 1.了解模块的内容: 2.掌握模块的创建和导入方式: 3.了解包结构的创建和使用. 二.实验环境 软件版本:Python 3.10 64_bit 三.实验过程 1.实 ...
- CH565/CH569W ETH-MAC例程现象使用说明
ETH-GMAC例程 使用MounRiver Studio(MRS)打开工程. 点击编译按键,编译完成出现0错误,0警告. 打开WCHISPTOOLS,芯片型号选择CH569或者CH565(根据评估版 ...
- 重新捋一捋React源码之更新渲染流程
前言 前些天在看Dan Abramov个人博客(推荐阅读,站在React开发者的角度去解读一些API的设计初衷和最佳实践)里的一篇文章,其重点部分的思想就是即使不使用Memo(),也可以通过组合的方式 ...