鲁迅:这可是道难题呢!

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


某改题毕,但见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. Delph i2010

    我在习惯Delphi2010 转载   一直留着一个txt文件,不晓得是干嘛的(忘记了),偶然打开一看.乖乖~ 2010 还可以这样玩. 1.循环有了新用法 procedure TForm1.Butt ...

  2. Redis基于主从复制的RCE(redis4.x 5.x)复现

    使用docker建立redis 拉取镜像 运行 查看 可以连接,存在未授权 https://github.com/Ridter/redis-rce 发送poc i:正向连接 r:反弹 反弹成功

  3. 20130330 printf数组改变 数组指针便利二维数组 二级指针遍历二维数组 ZigZag

    1.为什么printf之后数组的值会改变? #include<stdio.h> ; int * Zigzag() { ,j=,limit=; ; ; int a[N][N]; int (* ...

  4. linux最常用vim命令记录

    先来一张图了解3种模式: 一.输入vim 命令,进入命令模式 此时可执行: 1.行号显示 (1):set nu    显示文本的行号:    :nonu 取消显示行号 2.光标移动 (1)n<E ...

  5. 为什么 TCP 建立连接是三次握手,关闭连接确是四次挥手呢?

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:小书go https://blog.csdn.net/qzcsu/article/details/72861891 背 ...

  6. Codeforces Round #525 E - Ehab and a component choosing problem

    题目大意: 在一棵树中 选出k个联通块 使得 这k个联通块的点权总和 / k 最大 并且这k个联通块不相互覆盖(即一个点只能属于一个联通块) 如果有多种方案,找到k最大的那种 给定n 有n个点 给定n ...

  7. HTML_案例(注册案例CSS版)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 【JZOJ6293】迷宫

    description analysis 有没有想起[\(NOIP2018\)]保卫王国? 设\(tr[t][x][y]\)表示线段树上的\(t\)节点代表的区间,从最左边列的\(x\)行到最右边列\ ...

  9. Idea jsp页面乱码

    jsp页面中添加 <%@ page language="java" contentType="text/html; charset=utf-8" page ...

  10. 深入解读阿里云数据库POLARDB核心功能会话读一致性

    POLARDB架构 我们知道,POLARDB是一个由多个节点构成的数据库集群,一个主节点,多个读节点.对外默认提供两个地址,一个是集群地址,一个是主地址,推荐使用集群地址,因为它具备读写分离功能可以把 ...