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不等式的更多相关文章

  1. 2018百度之星初赛B - A,D,F

    总结:这一次的百度之星之行到这里也就结束了,充分的认识到了自己的不足啊...果然还是做的题太少,,见识的题型也还太少,对于STL的掌握还是不够到位啊!!(STL大法是真的好,建议大家认认真真的好好学学 ...

  2. 2018 百度之星 初赛 第六题 HDU6349

    三原色图  Accepts: 281  Submissions: 1261  Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 262144/ ...

  3. 百度之星初赛2A 1001 ALL X(HDU 5690)

    All X Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  4. 2018百度之星初赛(A)2 度度熊学队列

    思路: 记录一下c++ stl中的双向链表list的各种用法. https://blog.csdn.net/fanyun_01/article/details/56881515 实现: #includ ...

  5. 【2018百度之星初赛(A)】1002 度度熊学队列

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6375 Knowledge Point: STL - map:https://www.cnblogs.c ...

  6. 2018百度之星初赛B轮 p1m2

    p1m2 Accepts: 954 Submissions: 4063 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/1310 ...

  7. 2018百度之星初赛B轮 rect

    rect Accepts: 1654 Submissions: 2948 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131 ...

  8. 2018百度之星初赛A轮 度度熊拼三角

    #include<bits/stdc++.h> using namespace std; int n; int a[1005]; int main() {     int ans;     ...

  9. 2018百度之星初赛A轮 度度熊学队列

    注意:刚开始用数组存deque<int> qa[MAX]会爆内存 需要改用map<int, deque<int> > qa优化 不明觉厉 #include<b ...

随机推荐

  1. Html.PartialView(),html.Renderpartial,html.action.html.RenderAction 辅助方法

    Html.Partial(), 返回HTML字符串 .参数为部分视图 html.RenderPartial(),不返回返回HTML字符串 ,直接输出响应流.参数为部分视图 一般用于主视图中已经存在了这 ...

  2. myeclipse 导入maven

    一安装maven 先安装jdk,配置JAVA_HOME 把下载的maven bin包,解压到指定目录,比如:D:\apache-maven-3.3.9-bin 配置maven的系统变量M2_HOME和 ...

  3. NDK相关收藏【转】

    http://blog.csdn.net/column/details/anidea-ndk.html   [转] 作者:conowen@大钟

  4. bzoj 3979: [WF2012]infiltration【瞎搞+随机化】

    参考:https://www.cnblogs.com/ccz181078/p/5622200.html 非常服气.jpg 就是random_shuffle几次然后顺着找,ans取min... #inc ...

  5. Python圈中的符号计算库-Sympy(转载)

    <本文来自公众号“大邓带你玩python”,转载> import math math.sqrt(8) 2.8284271247461903 我们看看Python中结果 math.sqrt( ...

  6. 557. 反转字符串中的单词 III

    给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输出: &q ...

  7. poj 2195 Going Home (km算法)

    题目链接: http://poj.org/problem?id=2195 解题思路: 把man和home都提取出来,然后算出每个man和home的距离算出来,然后建立匹配图,套用km算法的模板,求最小 ...

  8. _bzoj1015 [JSOI2008]星球大战starwar【并查集】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1015 倒过来做就ok了. #include <cstdio> #include ...

  9. 积分图像的应用(一):局部标准差 分类: 图像处理 Matlab 2015-06-06 13:31 137人阅读 评论(0) 收藏

    局部标准差在图像处理邻域具有广泛的应用,但是直接计算非常耗时,本文利用积分图像对局部标准差的计算进行加速. 局部标准差: 标准差定义如下(采用统计学中的定义,分母为): 其中. 为了计算图像的局部标准 ...

  10. TCP模型,控制标志,握手,挥手,长连接*

    1. TCP协议 Transmission Control Protocol,传输控制协议 面向连接的协议 需要三次握手建立连接 需要四次挥手断开连接 TCP报头最小长度:20字节 2.模型图 3.T ...