瞬间移动

题意:构造一个所有点出度都为m的有向图最小化图的直径。

显然转成m进制来做就好了。

#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std; int read_p,read_ca;
inline int read(){
read_p=;read_ca=getchar();
while(read_ca<''||read_ca>'') read_ca=getchar();
while(read_ca>=''&&read_ca<='') read_p=read_p*+read_ca-,read_ca=getchar();
return read_p;
}
queue <int> q;
int n,m,dis[],mmh=;
inline int bfs(int x){
int mmh=,i,j,k;
for (i=;i<n;i++) dis[i]=1e9;dis[x]=;
q.push(x);
while (!q.empty()) for (mmh=dis[k=q.front()],q.pop(),i=;i<m;i++) if (j=(k*m+i)%n,dis[j]>dis[k]+) dis[j]=dis[k]+,q.push(j);
return mmh;
}
int main(){
register int i,j;
n=read();m=read();
for (i=;i<n;i++) mmh=max(mmh,bfs(i));
printf("%d\n",mmh);
for (i=;i<n;i++,puts(""))
for (j=;j<m;j++) printf("%d ",(i*m+j)%n);
}

hackerrank Diameter Minimization的更多相关文章

  1. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  2. 三维网格去噪算法(L0 Minimization)

    [He et al. 2013]文章提出了一种基于L0范数最小化的三角网格去噪算法.该思想最初是由[Xu et al. 2011]提出并应用于图像平滑,假设c为图像像素的颜色向量,▽c为颜色向量的梯度 ...

  3. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  4. HackerRank "Minimum Penalty Path"

    It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...

  5. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

  6. Diameter消息应用层路由

    1. 创建和发送Request消息: 1) 产生一个Request消息时,必须遵守下列规则: · 设置头部的Command code: · 设置头部的 'R' 位: · 设置头部的End-to-End ...

  7. HackerRank Extra long factorials

    传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...

  8. HackerRank "Lucky Numbers"

    Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...

  9. HackerRank "Playing with numbers"

    This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...

随机推荐

  1. 轨迹系列——Socket总结及实现基于TCP或UDP的809协议方法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 在上一篇博客中我详细介绍了809协议的内容.809协议规范了通 ...

  2. iOS 设置视图背景的透明度

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #00afca } span.s1 { color: #fffff ...

  3. HTTP Live Streaming 直播(iOS直播) 初识

    HTTP Live Streaming(HLS)技术,并实现了一个HLS编码器HLSLiveEncoder,当然,C++写的.其功能是采集摄像头与麦克风,实时进行H.264视频编码和AAC音频编码,并 ...

  4. ucore lab1 bootloader学习笔记

    ---恢复内容开始--- 开机流程回忆 以Intel 80386为例,计算机加电后,CPU从物理地址0xFFFFFFF0(由初始化的CS:EIP确定,此时CS和IP的值分别是0xF000和0xFFF0 ...

  5. 浅谈传统语音通信和APP语音通信音频软件开发之不同点

    本人在传统的语音通信公司做过手机和IP电话上的语音软件开发,也在移动互联网公司做过APP上的语音软件开发.现在带实时语音通信功能的APP有好多,主流的有微信语音.QQ电话.钉钉等,当然也包括我开发过的 ...

  6. python 嵌套字典比较值,取值

    #取值import types allGuests = {'Alice': {'apples': 5, 'pretzels': {'12':{'beijing':456}}}, 'Bob': {'ha ...

  7. python内置函数与匿名函数

    内置函数 Built-in Functions abs() dict() help() min() setattr() all() dir() hex() next() slice() any() d ...

  8. Python学习_10__python2到python3

    同样作为动态语言,python的面相对像和ruby有很多类似的地方,这里还是推荐<Ruby元编程>一书来参考学习python的面向对象.然而python并不是纯面向对象设计,所以很多rub ...

  9. GpG使用指南

    1. 简介 1991年,程序员Phil Zimmermann为了避开政府监视,开发了加密软件PGP.这个软件非常好用,迅速流传开来,成了许多程序员的必备工具.但是,它是商业软件,不能自由使用.所以,自 ...

  10. iOS pods-xxxx-frameworks.sh:permission denied问题

    找到Build Phases, 点开Embed Pods Frameworks 是不是看到了"${SRCROOT}/Pods/Target Support Files/Pods/Pods-f ...