【2018百度之星初赛 B】1001并查集 1004二分 1006不等式
1001 degree
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6380
并查集向图中加点,分别记录与初始度数最多的点 直接相连的点数、独立的点数;则间接相连的点数 = n-1-直接相连的点数;
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
using namespace std; int T,n,m,k;
int f[], a[]; int find(int x) {
if(f[x]!=x)
f[x]=find(f[x]);
return f[x];
} void Union(int x, int y) {
int w = find(x);
int s = find(y);
f[w] = s;
} int main()
{
cin>>T;
while(T--)
{
cin>>n>>m>>k;
for(int i=; i<n; i++) {
a[i]=; f[i]=i;
}
int maxn=, maxx=;
for(int x,y,i=; i<m; i++) {
cin>>x>>y;
Union(x, y);
if(x==y) continue;
a[x]++, a[y]++;
if(a[x]>maxn) maxx=x, maxn=a[x];
if(a[y]>maxn) maxx=y, maxn=a[y];
} int root = find(maxx);
for(int i=; i<n; i++) {
int t = find(i);
if(t==i && t!=root) maxn++;
} int dir = n-maxn-;
if(k>=dir) maxn=n-;
else maxn+=k; if(!n) maxn = ;
cout<<maxn<<endl;
}
return ;
}
1004 p1m2
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6383
找出数列中最大值和最小值,二分枚举答案,对于每一个答案都循环计算一次;思想同二分查找,每次答案所在区间缩小一半;
#include<iostream>
#include<algorithm>
using namespace std; #define min(a,b) a>b?b:a
#define LL long long
const int N = ;
LL T, n, a[N]; int main()
{
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
cin>>n;
LL minn=1e9, maxn=-;
for(int i=; i<n; i++) {
cin>>a[i];
minn = min(a[i], minn);
maxn = max(a[i], maxn);
} while(minn <= maxn) {
LL mid = (minn+maxn)/, tmp = ;
for(int i=; i<n; i++) {
if(a[i]>mid) tmp += (a[i]-mid)/;
else tmp += a[i]-mid;
}
if(tmp<)
maxn = mid-;
else
minn = mid+;
}
cout<<maxn<<endl;
} return ;
}
1006 rect
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6385
假设有交叉线的情况存在,对这种假设列满足条件的不等式,发现矛盾,所以不存在交叉线情况;
#include<iostream>
using namespace std; #define min(a,b) a>b?b:a
#define LL long long
int T;
LL mx, my, n; int main()
{
cin>>T;
while(T--) {
cin>>mx>>my>>n; LL ans=;
int x,y;
for(int i=; i<n; i++) {
cin>>x>>y;
if(x<=mx/ && y<=my/) ans += min(x,y);
else if(x>=mx/ && y<=my/) ans += min(mx-x, y);
else if(x>=mx/ && y>=my/) ans += min(mx-x, my-y);
else if(x<=mx/ && y>=my/) ans += min(x, my-y);
}
cout<<ans<<endl;
} return ;
}
【2018百度之星初赛 B】1001并查集 1004二分 1006不等式的更多相关文章
- 2018百度之星初赛B - A,D,F
总结:这一次的百度之星之行到这里也就结束了,充分的认识到了自己的不足啊...果然还是做的题太少,,见识的题型也还太少,对于STL的掌握还是不够到位啊!!(STL大法是真的好,建议大家认认真真的好好学学 ...
- 2018 百度之星 初赛 第六题 HDU6349
三原色图 Accepts: 281 Submissions: 1261 Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 262144/ ...
- 百度之星初赛2A 1001 ALL X(HDU 5690)
All X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2018百度之星初赛(A)2 度度熊学队列
思路: 记录一下c++ stl中的双向链表list的各种用法. https://blog.csdn.net/fanyun_01/article/details/56881515 实现: #includ ...
- 【2018百度之星初赛(A)】1002 度度熊学队列
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6375 Knowledge Point: STL - map:https://www.cnblogs.c ...
- 2018百度之星初赛B轮 p1m2
p1m2 Accepts: 954 Submissions: 4063 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/1310 ...
- 2018百度之星初赛B轮 rect
rect Accepts: 1654 Submissions: 2948 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131 ...
- 2018百度之星初赛A轮 度度熊拼三角
#include<bits/stdc++.h> using namespace std; int n; int a[1005]; int main() { int ans; ...
- 2018百度之星初赛A轮 度度熊学队列
注意:刚开始用数组存deque<int> qa[MAX]会爆内存 需要改用map<int, deque<int> > qa优化 不明觉厉 #include<b ...
随机推荐
- bzoj 2528: [Poi2011]Periodicity【kmp+构造】
神仙构造,做不来做不来 详见:http://vfleaking.blog.163.com/blog/static/174807634201329104716122/ #include<iostr ...
- bzoj 1597: [Usaco2008 Mar]土地购买【斜率优化】
按xy降序排序,把能被完全包含的去掉 然后就得到了x升序y降序的一个数组 然后方程就显然了:f[i]=min(f[j]+y[j+1]x[i]) 斜率优化转移 说起来我还不会斜率优化呢是不是该学一下了 ...
- 关于python安装lxml插件的问题
文章只是介绍自己安装时从安装不上到安装后报错,再到安装成功的心路历程,并不代表广大欧皇也会会出现同类型的问题,也不是总结和汇总各种出问题的原因. 直接进入正题,首先我这边是win环境,电脑上装的是py ...
- 报错Cannot determine embedded database driver class for database type NONE解决方法
由于我不需要数据库,启动springboot报错: Cannot determine embedded database driver class for database type NONE If ...
- Lightoj 1174 - Commandos (bfs)
题目链接: Lightoj 1174 - Commandos 题目描述: 有一军队秉承做就要做到最好的口号,准备去破坏敌人的军营.他们计划要在敌人的每一个军营里都放置一个炸弹.军营里有充足的士兵,每 ...
- ACM二分查找模板
int main(){ == key int m; while ( l <= r ) { m = ( l + r ) >> 1; if ( x[m] == key ) return ...
- stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram
题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...
- 数学 SCU 4436 Easy Math
题目传送门 /* 数学题:当有一个数开根号后是无理数,则No */ #include <cstdio> #include <algorithm> #include <cs ...
- dubbo服务端响应超时错误一例记录
错误描述: Portlet J2AppsPortlet::QuickStartPortlet not available: Waiting server-side response timeout. ...
- 转 Oracle Transportable TableSpace(TTS) 传输表空间 说明
############1 迁移数据库的集中方法 三.相关技术 迁移方式 优势 不足1 Export and import • 对数据库版本,以及系统平台没有要求 • 不支持并发,速度慢• 停机时 ...