淼一淼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 ...
随机推荐
- Apache Shiro RememberMe 1.2.4 反序列化漏洞
拉取镜像 docker pull medicean/vulapps:s_shiro_1 启动环境 docker run -d -p 80:8080 medicean/vulapps:s_shiro_1 ...
- neo4j常用cypher语句
阅读更多 1.删除带有关系的节点 a.先删除关系 match (n:Node)-[r:关系名称]-() where (n...条件) delete r b.删除节点 match (n:Node ...
- Appium 微信 webview 的自动化技术
Appium 微信 webview 的自动化技术 最近好多人问微信webview自动化的事情, 碰巧我也在追微信webview的自动化和性能分析方法. 先发出来一点我的进展给大家参考下. 此方法用 ...
- 宝塔面板安装swoole扩展
Swoole是一个PHP扩展,扩展不是为了提升网站的性能,是为了提升网站的开发效率.最少的性能损耗,换取最大的开发效率.利用Swoole扩展,开发一个复杂的Web功能,可以在很短的时间内完成 Swoo ...
- virtualbox启动虚机报错:The VM session was closed before any attempt to power it on.
解决方法: image.png 点击清除即可. 或者在控制>清除保存的状态.然后重启虚机即可!
- WPF 新突破
刘琦告诉我 需要改变哪个属性哪个属性就需要实现InotifyPropertyChanged 董秀伟告诉我 界面改变会立即传输到属性上,并不需要实现InotifyPropertyChanged,只有 ...
- thinkphp 控制器定义
控制器和操作 一般来说,ThinkPHP的控制器是一个类,而操作则是控制器类的一个公共方法. 下面就是一个典型的控制器类的定义: <?php namespace Home\Controller; ...
- 现金贷平台下载量TOP100 涉逾30家P2P
一.什么是现金贷,现状如何 那么什么是现金贷呢?在笔者看来,狭义的现金贷主要是指基于互联网等技术手段的小额现金贷款,广义的现金贷可以包括任何以小额现金和存款为标的进行借贷的行为,是一种无担保.无抵押. ...
- niginx相关命令及代理配置
安装 in mac https://www.cnblogs.com/meng1314-shuai/p/8335140.html Nginx相关命令 mac下启动: 通过brew 安装install 后 ...
- Vue基础(1)
目录 Vue基础 基础 导入 1. 挂载 2. 插值表达式 3. 事件 4. 创建对象 5. v-text和v-html 6. vue的过滤器 7. 属性指令 Vue基础 基础 首先我们要知道Vue是 ...