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. JS获得本月的第一天和最后一天

    <script> //本月第一天  function showFirstDay()  {      var Nowdate=new Date();      var MonthFirstD ...

  2. IDEA Terminal

    如果IDEA在Terminal中无法使用环境变量,提示没有此命令的话,请查看在cmd中是否可以正常使用,然后,请右击IDEA以管理员方式进行运行,Terminal就可以正常使用了

  3. E20180128-hm

    paradigm  n. 范例,样式,模范; 词形变化表; outlet  n. 出口,出路; 批发商店; 排水口,通风口; 发泄(情感)的方法;

  4. MySQL(调优慢查询、explain profile) 转

    转自http://www.linuxidc.com/Linux/2012-09/70459.htm mysql profile explain slow_query_log分析优化查询 在做性能测试中 ...

  5. bzoj 1089: [SCOI2003]严格n元树【dp+高精】

    设f[i]为深度为i的n元树数目,s为f的前缀和 s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种 写个高精就行了,好久没写WA了好几次-- #incl ...

  6. window 下拉取github项目失败 (Permission denied (publickey))

    原因是github 帐号ssh 失效或者没有配置 1.找到gitcmd 并进入 2.在gitcmd 下切换到 安装git路劲\Git\usr\bin 3.提示在C:\Users\Administrat ...

  7. spring boot启动报错Error starting ApplicationContext(未能配置数据源)

    主要错误:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource c ...

  8. jQuery笔记之data方法

    成品图如下所示: 搭建HTML+CSS结构 <style> /* 给tpl设置为不可见,因为我们不需要用到他,我们只是要克隆他身上的东西,克隆完就把他删掉.就跟渣男一样!!!*/ .tpl ...

  9. [BZOJ4043/CERC2014]Vocabulary

    Description 给你三个字符串,这些字符串有些单词模糊不可认了,用"?"来代表. 现在你可以用任意英文小写字母来代表它们.要求是使得给定的三个字符串中 所有的"? ...

  10. 官方XmlPullParser和网络解析xml示例及详述

    Parsing XML Data This lesson teaches you to Choose a Parser Analyze the Feed Instantiate the Parser ...