让你构造一棵树(给定了总结点数和总的叶子数),使得直径最小。

就先弄个菊花图(周围一圈叶子,中间一个点),然后平均地往那一圈放其他的点即可。

#include<cstdio>
using namespace std;
int n,K,Ks[200010],x[200010],y[200010],ans,e;
int main(){
scanf("%d%d",&n,&K);
for(int i=1;i<=K;++i){
Ks[i]=1;
}
int now=2;
for(;;){
for(int i=1;i<=K;++i,++now){
if(now>n){
goto OUT;
}
x[++e]=Ks[i];
y[e]=now;
Ks[i]=now;
if(i==1){
++ans;
}
else if(i==2){
++ans;
}
}
}
OUT:
printf("%d\n",ans);
for(int i=1;i<=e;++i){
printf("%d %d\n",x[i],y[i]);
}
return 0;
}

【构造】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) B. High Load的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D 构造烟花

    D. High Load time limit per test 2 seconds memory limit per test 512 megabytes input standard input ...

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

    题目链接:http://codeforces.com/contest/828 A. Restaurant Tables time limit per test 1 second memory limi ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. word 宏,脚本编程

    '脚本方式新建word 再新建文档,文档中输入字符串"你好" Dim wdapp As Word.Application Dim wddoc As Word.Document Se ...

  2. python基础===【爬虫】爬虫糗事百科首页图片代码

    import requests import re import urllib.request def getHtml(url): page = requests.get(url) html = pa ...

  3. sublime Text3 === 无法输入input的问题解决办法

    sublimetext无法对input或者raw_input执行.因此搜了很多方法后,解决了这个问题: 1.先下载插件sublimerepl ,如果无法下载,请点击https://github.com ...

  4. Sql Server 2014/2012/2008/2005 数据库还原出现 3154错误的解决办法

    在Sql Server  数据库还原出现 3154错误 解决方法1:不要在数据库名字上点右键选择还原,而要是在根目录“数据库”三个字上点右键选择还原,然后再选择数据库,问题便可以解决,如果不行参照方法 ...

  5. 在Github里集成Readthedocs服务

    Readthedocs支持Markdown格式和sphinx格式的文档排版,是部署项目文档的绝佳平台.利用Github的托管服务,我们可以方便地将文档托管于Github,并利用Readthedocs查 ...

  6. 生命周期(vue的钩子函数)

    生命周期图示 创建前,创建后,挂载前,挂载后,更新前,更新后,销毁前,销毁后 beforeCreate:function(){ console.log('1-beforeCreate 组件还未被创建' ...

  7. SQL利用Case When Then多条件判断SQL 语句

    http://www.cnblogs.com/kevin2013/archive/2010/07/02/1769682.html SQL利用Case When Then多条件判断SQL ,用于sele ...

  8. 【python】r+,w+ 全局变量

    来源:http://www.educity.cn/wenda/352188.html r+:可读可写,若文件不存在,报错w+: 可读可写,若文件不存在,创建文本模式:遇换行符时根据操作系统不同自动转换 ...

  9. linux命令(40):at命令

    1.命令格式: at[参数][时间] 2.命令功能: 在一个指定的时间执行一个指定任务,只能执行一次,且需要开启atd进程( ps -ef | grep atd查看, 开启用/etc/init.d/a ...

  10. LeetCode解题报告—— Swap Nodes in Pairs & Divide Two Integers & Next Permutation

    1. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For e ...