鲁迅:这可是道难题呢!

鲁迅:我没说过这话,不过确实在理。


某改题毕,但见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的更多相关文章

  1. Problem 1108 - 淼·诺贝尔

    #include<iostream> #include<vector> #include<algorithm> using namespace std; struc ...

  2. 30天,APP创业从0到1【7.25上海站】

    活动概况 时间:2015年7月25日13:30-16:30 地点:太库•上海孵化器(张江金科路2889号长泰广场c座12楼) 主办:APICloud.诸葛.圣诺资讯 联合主办:微链.太库•上海孵化器 ...

  3. 云计算:创业的好时机——上海够快网络科技有限公司总经理蒋烁淼专访(评价阿里云的OSS的4个优点)(够快科技正式宣布已成功挂牌新三板)

    云存储是云计算目前的热点之一,Dropbox.Box等产品的风靡,公司因此获得极高估值,都印证了这一点.但云存储对技术和资金要求都比较高,竞争也非常激烈,挑战巨大.国外云存储公司有亚马逊的云平台作为支 ...

  4. “不是不需要运维工程师,是人人皆是运维”|对话阿里云MVP蒋烁淼(上)

    摘要: 与湖畔大学首期学员.阿里云MVP.驻云创始人蒋烁淼面对面 [三位阿里云MVP(驻云CEO.首席架构师.大数据总监)<MVP时间>首次同台授课,“湖畔第一大脑” 蒋烁淼领头线上精讲, ...

  5. 陈思淼:阿里6个月重写Lazada,再造“淘宝”的技术总结

    小结: 1. 所谓的中台技术,就是从 IDC,网络,机房,操作系统,中间件,数据库,算法平台,数据平台,计算平台,到业务平台,每一层都有清晰的定义和技术产品. 具体来看,首先,集团技术的分层和每层的产 ...

  6. HDOJ-1017 A Mathematical Curiosity(淼)

    http://acm.hdu.edu.cn/showproblem.php?pid=1017 # include <stdio.h> int find(int n, int m) { in ...

  7. 中山纪中集训Day5叒是测试(划淼)

    A组T1 矩阵游戏(game) 九校联考24OI__D1T1 问题描述 LZK发明一个矩阵游戏,大家一起来玩玩吧,有一个N行M列的矩阵.第一行的数字是1,2,…M,第二行的数字是M+1,M+2…2*M ...

  8. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  9. 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 ...

随机推荐

  1. Java 核心编程技术干货,2019 最新整理版!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 以下是Java技术栈微信公众号发布的所有关于 Java 的技术干货,会从以下几个方面汇总,本文会长期更新. Java 基础篇 ...

  2. [每日一个小技巧] CentOS 下使用yum安装一类软件包

    版权声明:本文为博主原创文章,欢迎转载,转载请注明出处. https://blog.csdn.net/robertsong2004/article/details/37775313 yum 提供了丰富 ...

  3. 唯一id

    package com.debug.kill.server.utils; /** * Created by Administrator on 2019/6/20. */ import org.apac ...

  4. yii2使用vendor文件夹下的的css文件

    yii2 使用 vendor 下在css样式, 可以新建一个Asset,定义 public $sourcePath="@vendor/..",如:public $sourcePat ...

  5. Cut the Sequence

    Cut the Sequence 有一个长度为n的序列\(\{a_i\}\),现在求将其划分成若干个区间,并保证每个区间的和不超过m的情况下,每个区间的最大值的和的最小值,\(0 < N ≤ 1 ...

  6. 挂载U盘

    .fdisk -l 查看当前系统存储盘 (sdaX一般是系统自带, sdbX则是外接) .mount /dev/sdbX /mnt/usb/ (如果usb目录不存在可创建新目录) .umount /m ...

  7. HDU 6064 RXD and numbers

    传送门 有向图生成树计数 (度数 ->入度->外向树) BEST定理 (不定起点的欧拉回路个数=某点为根的外向树个数(存在欧拉回路->每个点为根的外向树个数相等)*(每个点的度数(存 ...

  8. webstorm 初次上传代码到 远程gitlab中

    1. 在 公司搭建的gitlab网站,创建project,然后生成了 git的地址. 2.在 本地电脑上,打开 webstorm,要将已有的代码上传到 git网站,那么需要在webstrom编辑器的t ...

  9. FHS 文件层次标准

    FHS:文件层次标准 操作系统自身运行使用的 /bin: 存放可执行的二进制程序,管理员和普通用户都可以使用 /sbin:管理员才能执行的命令 运行正常功能的程序存放位置 /usr/bin /usr/ ...

  10. 伪造ip头

    x-forwarded-for: 127.0.0.1x-remote-IP: 127.0.0.1x-remote-ip: 127.0.0.1x-client-ip: 127.0.0.1x-client ...