淼一淼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中文件名函数-路径、名称、子目录、驱动器、扩展名
文件名函数 文件名函数可以对文件的名称.所在子目录.驱动器和扩展名等进行操作.下表列出这些函数及其功能. 函数说明 ExpandFileName() //返回文件的全路径(含驱动器.路径) Extra ...
- PAT_A1090#Highest Price in Supply Chain
Source: PAT A1090 Highest Price in Supply Chain (25 分) Description: A supply chain is a network of r ...
- Scala 学习2
去map里面的数据 scala> val map = Map("a"->1, "b"->2, "c"->3) map ...
- C++之运算符_算数运算符
运算符 **作用:**用于执行代码的运算 | **运算符类型** | **作用** || -------------- | -------------------------------------- ...
- 三层(3-tier architecture)基础
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/lhc2207221755/article/details/24802053 之前看过非常多关 ...
- springboot项目中使用设计模式一策略模式
策略模式: 使用常用,支付,之前做了微信支付,支付宝支付,然后另外一个同事写了一个银联支付,那么如果代码方法一起就会导致代码不是很好操作所以,采用策略模式进行,同事只需要写一个实现类,就可以了, 在协 ...
- ES6 学习 -- Set和Map数据结构
一.Set对象数据结构 1.Set数据结构类似数组,但是其每个成员都是唯一值,没有重复,且Set本身是一个构造函数,用来生成Set数据结构,用法如下: const setData = new Set( ...
- Task ProgressBar模拟现实完成后显示TextBox
private async void Form1_Load(object sender, EventArgs e) { progressBar1.Maximum = ; progressBar2.Ma ...
- The linux command 之定制提示符
一.提示符分解 默认提示符如下所示: [me@linuxbox ~]$ 可以看出它包括我们的用户名.主机名.当前工作目录.提示符是由PS1变量定义的. [me@linuxbox ~]$ echo $P ...
- BCZM : 1.5
https://blog.csdn.net/zs634134578/article/details/18046317 有很多服务器存储数据,假设一个机器仅存储一个标号为ID的记录,假设机器总量在10亿 ...