Codeforces 828D High Load (构造)
来源:互联网 发布:淘宝哪个返利多 编辑:程序博客网 时间:2024/05/29 19:34
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of nnodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability.
Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes.
Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.
The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes.
Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints.
In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to n. Exit-nodes can have any ids.
If there are multiple answers, print any of them.
3 2
21 22 3
5 3
31 22 33 43 5
In the first example the only network is shown on the left picture.
In the second example one of optimal networks is shown on the right picture.
Exit-nodes are highlighted.
网上的写法复杂了,发一发简单的(逃。
#include<bits/stdc++.h>using namespace std;int main(){ int n, k; scanf("%d%d",&n,&k); int ans = (n - 1) / k; ans = ans * 2; if((n - 1) % k > 0) ans++; if((n - 1) % k > 1) ans++; printf("%d\n",ans); queue<int> q; for(int i = 2; i <= k + 1; i++){ q.push(i); printf("1 %d\n",i); } for(int i = k + 2; i <= n; i++){ printf("%d %d\n",i,q.front()); q.pop(); q.push(i); }}
- Codeforces 828D High Load (构造)
- Codeforces 828 D. High Load 思维+构造
- Codeforces 828 D High Load
- codeforces 423 D. High Load 构造一个思维的树
- Codeforces 827B. High Load 【构造】
- Codeforces Round #423 D. High Load
- Codeforces Round #423 D. High Load
- Codeforces Round #423 (Div. 2) C. String Reconstruction思维 D. High Load 构造
- CodeForces 828D High Road
- Codeforces 828D High Load【贪心+求树的最长链】
- CF827B:High Load(树 & 构造)
- Codeforces Round #423 (Div. 2) D High Load 贪心,树
- Codeforces Round #423 (Div. 2) D. High Load
- Codeforces828 D. High Load
- High Load CodeForces
- Codeforces 875D High Cry
- CodeFroces 827B. High Load(构造法)
- CodeForces 865D Buy Low Sell High(思维)
- Noip2015 斗地主【搜索】【贪心】
- 自动更新packagejson
- 图像的矩
- Tomcat共用Session实现SSO单点登录
- 5步做一个 TensorFlow 聊天机器人:DeepQA
- Codeforces 828D High Load (构造)
- 企业级旅行App源码、高仿爱鲜蜂源码、iOS Arkit测距源码等
- 图片局部马斯克demo展示
- 【错误记录】
- 02 STM32启动文件的理解
- 用photoshop去掉图片文字
- akka spark sbt依赖冲突
- HTC-VIVE手柄使用代码
- 在服务器上跑java程序