淼一淼A+B problem
鲁迅:这可是道难题呢!
鲁迅:我没说过这话,不过确实在理。
某改题毕,但见LOJ之上有数「A+B」之AC记录。余亦尝闻A+B之趣味无穷,遂兴起而码之。
少顷,AC之,吾心所畅。
#include<iostream>
#include<cstdio>
#include<algorithm>
#define rint register int
using namespace std;
int a,b,tot,first[],cnt,ans=,fa[];
struct node{int u,v,w,nxt;}edge[];
inline bool cmp(node uu,node vv){return uu.w<vv.w;}
inline void add(int uu,int vv,int ww)
{
edge[++tot]=(node){uu,vv,ww,first[uu]};
first[uu]=tot;
}
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void kruskal()
{
int sum=;
sort(edge+,edge+tot+,cmp);
for(rint i=;i<=cnt;++i)fa[i]=i;
for(rint i=;i<=tot;++i)
{
int x=find(edge[i].u),y=find(edge[i].v);
if(x!=y)
{
fa[y]=x;sum++;
ans+=edge[i].w;
}
if(sum==cnt-)return ;
}
}
int main()
{
scanf("%d %d",&a,&b);
cnt=;add(,,a),add(,,a);
add(,,b),add(,,b);
kruskal();
cout<<ans<<endl;
return ;
}
Kruskal
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rint register int
using namespace std;
int a,b,tot,first[],cnt,ans=;
int dist[];
bool vis[];
struct node{int u,v,w,nxt;}edge[];
inline void add(int uu,int vv,int ww)
{
edge[++tot]=(node){uu,vv,ww,first[uu]};
first[uu]=tot;
}
inline void dijkstra(int x)
{
memset(dist,0x7f,sizeof(dist));
dist[x]=;
for(rint i=;i<cnt;++i)
{
int k=;
for(rint j=;j<=cnt;++j)
if(!vis[j]&&(k==||dist[j]<dist[k]))
k=j;
vis[k]=;
for(rint j=first[k];j;j=edge[j].nxt)
{
int y=edge[j].v;
dist[y]=min(dist[y],edge[j].w+dist[k]);
}
}
return ;
}
int main()
{
scanf("%d %d",&a,&b);
cnt=;add(,,a),add(,,b);
dijkstra();
cout<<dist[]<<endl;
return ;
}
dijkstra
#include<iostream>
#include<cstdio>
#include<algorithm>
#define rint register int
using namespace std;
int a,b,l,r;
int main()
{
l=,r=;
scanf("%d %d",&a,&b);
while(l<=r)
{
int mid=(l+r)>>;
if(a+b>mid)l=mid+;
else r=mid-;
}
cout<<l<<endl;
return ;
}
二分答案
淼一淼A+B problem的更多相关文章
- Problem 1108 - 淼·诺贝尔
#include<iostream> #include<vector> #include<algorithm> using namespace std; struc ...
- 30天,APP创业从0到1【7.25上海站】
活动概况 时间:2015年7月25日13:30-16:30 地点:太库•上海孵化器(张江金科路2889号长泰广场c座12楼) 主办:APICloud.诸葛.圣诺资讯 联合主办:微链.太库•上海孵化器 ...
- 云计算:创业的好时机——上海够快网络科技有限公司总经理蒋烁淼专访(评价阿里云的OSS的4个优点)(够快科技正式宣布已成功挂牌新三板)
云存储是云计算目前的热点之一,Dropbox.Box等产品的风靡,公司因此获得极高估值,都印证了这一点.但云存储对技术和资金要求都比较高,竞争也非常激烈,挑战巨大.国外云存储公司有亚马逊的云平台作为支 ...
- “不是不需要运维工程师,是人人皆是运维”|对话阿里云MVP蒋烁淼(上)
摘要: 与湖畔大学首期学员.阿里云MVP.驻云创始人蒋烁淼面对面 [三位阿里云MVP(驻云CEO.首席架构师.大数据总监)<MVP时间>首次同台授课,“湖畔第一大脑” 蒋烁淼领头线上精讲, ...
- 陈思淼:阿里6个月重写Lazada,再造“淘宝”的技术总结
小结: 1. 所谓的中台技术,就是从 IDC,网络,机房,操作系统,中间件,数据库,算法平台,数据平台,计算平台,到业务平台,每一层都有清晰的定义和技术产品. 具体来看,首先,集团技术的分层和每层的产 ...
- HDOJ-1017 A Mathematical Curiosity(淼)
http://acm.hdu.edu.cn/showproblem.php?pid=1017 # include <stdio.h> int find(int n, int m) { in ...
- 中山纪中集训Day5叒是测试(划淼)
A组T1 矩阵游戏(game) 九校联考24OI__D1T1 问题描述 LZK发明一个矩阵游戏,大家一起来玩玩吧,有一个N行M列的矩阵.第一行的数字是1,2,…M,第二行的数字是M+1,M+2…2*M ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
随机推荐
- delphi基础篇之单元文件
Delphi单元文件 unit MainFrm; {库单元文件头} interface {接口部分由Interface开始implementation结束.声明引用的单元,常量,数据类型 ...
- markdown开篇
def show(): print("你好世界!") print("实习的日子还是得好好学习呀!") print("加油 各位!")
- cv2.imwrite()指定图片存储路径
cv2.imwrite("./data/photo_{}.jpg".format(i), photo)
- python+tushare获取A股所有股票代码和名称列表
接口:stock_basic 描述:获取基础信息数据,包括股票代码.名称.上市日期.退市日期等 注:tushare模块下载和安装教程,请查阅我之前的文章 输入参数 名称 | 类型 ...
- finalize的作用
1. finalize的作用 finalize()是Object的protected方法,子类可以覆盖该方法以实现资源清理工作,GC在回收对象之前调用该方法. finalize()与C++中的析构函数 ...
- 使用CSS为图片添加更多趣味的5种方法
使用Photoshop为每个图片添加某种样式虽然可行,但会是相当乏味且困难的长久工作.下面要介绍的CSS技巧将帮助你从痛苦中解脱出来! 阴影效果 通过使用带有一些padding之的背景图来添加阴影效果 ...
- Docker学习のDocker和虚拟机
最初听到Docker,是作为虚拟机来宣传的,但是它本质不是虚拟机 一.虚拟机 虚拟机(Virtual Machine)指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离环境中的完整计算机系统. ...
- 2019牛客暑期多校训练营(第八场)I-Inner World DFS序+主席树(扫描线也可)
题目传送门 题意:初始有n棵树,每棵树都只有1个n号节点,现在有m次添加操作,每次操作是将$[l,r]$范围内的树的$u$节点后面添加一个$v$节点.每个v节点只会被添加一次. 然后是q次询问,输出$ ...
- SPR, subpixel rendering
参考例子:https://www.grc.com/ctwhat.htm https://en.wikipedia.org/wiki/Subpixel_rendering http://archernz ...
- python 基本常用数据类型
#字典类型 result={1:2222,2:2221111}; result.items();#获取字典中所有元素 result.keys();#获取字典的key result.values();# ...