D. High Load
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes 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.

Input

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.

Output

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.

Examples
Input
3 2
Output
2
1 2
2 3
Input
5 3
Output
3
1 2
2 3
3 4
3 5
Note

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.

题意:构造一个n点的树只有k个叶子结点 使得相离最远的两个叶子结点的距离最小

题解:看过烟花吧,就是那个样子的。

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n,k;
int main()
{
scanf("%d %d",&n,&k);
if((n-)%k==)printf("%d\n",(n-)/k*);
else if((n-)%k==) printf("%d\n",(n-)/k*+);
else printf("%d\n",(n-)/k*+);
int exm=(n-)%k;
int re=;
for(int j=;j<=k;j++){
int jishu=(n-)/k;
if(exm>)
{
jishu++;
exm--;
}
printf("1 %d\n",re);
for(int i=;i<=jishu;i++){
printf("%d %d\n",re,re+);
re++;
}
re++;
}
return ;
}

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D 构造烟花的更多相关文章

  1. Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals)

    Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...

  2. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

    E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

  3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块

    Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造

    D. High Load 题目连接: http://codeforces.com/contest/828/problem/D Description Arkady needs your help ag ...

  5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集

    C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...

  6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C

    A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...

  7. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  8. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  9. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Pronlem A In a small restaurant there are a tables for one person and b tables for two persons. It i ...

随机推荐

  1. 构建树形结构数据(全部构建,查找构建)C#版

    摘要: 最近在做任务管理,任务可以无限派生子任务且没有数量限制,前端采用Easyui的Treegrid树形展示控件. 一.遇到的问题 获取全部任务拼接树形速度过慢(数据量大约在900条左右)且查询速度 ...

  2. Scrum立会报告+燃尽图(十一月二十四日总第三十二次):视频剪辑

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...

  3. FivePlus——分工理解

    最终的游戏方案 游戏采用回合制,每回合双方英雄各自轮流选择移动和攻击以及大招,选择结束进行结算 英雄/小兵/塔的攻击力/大招效果参照作业要求,如果发现不均衡再进行调整 UI界面考虑使用QT或者命令行界 ...

  4. POJ 2392 Space Elevator 贪心+dp

    题目链接: http://poj.org/problem?id=2392 题意: 给你k类方块,每类方块ci个,每类方块的高度为hi,现在要报所有的方块叠在一起,每类方块的任何一个部分都不能出现在ai ...

  5. L1正则化与L2正则化的理解

    1. 为什么要使用正则化   我们先回顾一下房价预测的例子.以下是使用多项式回归来拟合房价预测的数据:   可以看出,左图拟合较为合适,而右图过拟合.如果想要解决右图中的过拟合问题,需要能够使得 $ ...

  6. 配置java环境 启动服务

    1:查看当前的Java JDK版本,是否符合要求,下载的为2.4.4版本,因此满足条件 [root@7 ~]# java -version openjdk version "1.8.0_65 ...

  7. MySQL 基于lvm2的备份实战演练 (快照备份)

    前言: lvm2实现热备的原理是基于lvm2的快照功能,lvm2可以实现数据集不大的情况下的热备. 实战过程如下:这里的演示是在一台Mariadb服务器上进行创建快照,将快照中的文件scp到备份服务器 ...

  8. 树莓派无显示器、无网线,优盘(U盘)启动,远程桌面

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:树莓派无显示器.无网线,优盘(U盘)启动,远程桌面     本文地址:http://techi ...

  9. SQL中INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN区别

    sql中的连接查询有inner join(内连接).left join(左连接).right join(右连接).full join(全连接)四种方式,它们之间其实并没有太大区别,仅仅是查询出来的结果 ...

  10. jquery中的append功能相当于剪切的作用 将原来的元素剪切走

    jquery中的append功能相当于剪切的作用 将原来的元素剪切走