D - High Load

因为要出口节点距离最小,所以除了根节点(根节点连接k个儿子)其他节点的儿子只能有一个,其他情况下的距离都比这个长,因为如果不是这样,那么根节点连接的子树数量就小与k,那么每个子树的长度就更长了(显然,画图可证)。

n-1个节点平均分配到k条子树上,如果画图的话,是这样的

只要讨论一下最后一层的的个数((n-1)%k)情况即可,连接方式也如上图。

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,k;
while(cin>>n>>k)
{
int m=(n-)/k;
if((n-)%k==)
{
cout<<m*<<endl;
}
else if((n-)%k==)
{
cout<<m*+<<endl;
}
else cout<<m*+<<endl;
int i=;
for(i=;i<=k+&&i<=n;i++)cout<<i<<' '<<<<endl;
while(i<=n)
{
cout<<i<<' '<<i-k<<endl;
i++;
}
}
return ;
}

Codeforces D - High Load的更多相关文章

  1. Codeforces E. High Load(构造)

    题目描述: High Load time limit per test 2 seconds memory limit per test 512 megabytes input standard inp ...

  2. 第一发。。。codeforces 609 C Load Balancing 贪心

    /*题意:给你一个序列经过最小变换,变换一次为一个数+1,一个数-1,使得最大值与最小值相差1:思路:与最后得到的序列相差的sum/2:*/#include<iostream> #incl ...

  3. CodeForce---Educational Codeforces Round 3 Load Balancing 正题

    看到这题是我的想法就是肯定跟平均值有关但是接下来就不知道怎么做了 看完大神的正解数之后,原来发现是这么简单,但是就是不知道为啥一定是平均值和平均值加1,而不是平均值和平均值减1: 好啦下面就贴出大神的 ...

  4. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

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

  6. CF# Educational Codeforces Round 3 C. Load Balancing

    C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Educational Codeforces Round 3 C. Load Balancing

    C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces 847H - Load Testing

    847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  9. codeforces 828 D. High Load(思维,水题)

    题目链接:http://codeforces.com/contest/828/problem/D 题解:任意去一个点为根然后有几个k就是几个子叶也就是根结点有几个分支然后最好的解法就是贪心,将剩下的点 ...

随机推荐

  1. 借root之名,行流氓之实,劝告,root需谨慎

    20160425++++++ 今日再回头看这篇文章,貌似有点偏激了一点,不过xda论坛上有个疑似kingroot开发团队的用户说明了kingroot确实对supersu做了限制,说是supersu在替 ...

  2. mysql的count方法详解

    1.cout(*)会统计为null的行: 2.count(列名)不会统计此列null值的行: 3.count(distinct col)计算该列除null之外的不重复数量:

  3. BufferedImage操作图片笔记(转)

    BufferedImage是Image的一个子类,BufferedImage生成的图片在内存里有一个图像缓冲区,利用这个缓冲区我们可以很方便的操作这个图片,通常用来做图片修改操作如大小变换.图片变灰. ...

  4. Unirest-拼装http请求发送rest接口

    public static Integer getInfo(String name) { HttpResponse<Integer> httpResponse = null; try { ...

  5. bzoj2733: [HNOI2012]永无乡 启发式合并

    地址:http://www.lydsy.com/JudgeOnline/problem.php?id=2733 题目: 2733: [HNOI2012]永无乡 Time Limit: 10 Sec   ...

  6. LR和SVM的相同和不同

    之前一篇博客中介绍了Logistics Regression的理论原理:http://www.cnblogs.com/bentuwuying/p/6616680.html. 在大大小小的面试过程中,经 ...

  7. 俞敏洪:未来教育是互联网+ AI +区块链联合颠覆

    “我对面向未来教育领域,内心是有一丝悲哀的.至少在我思考和理解的范围内,互联网和 AI 是不是有可能彻底的改变中国教育现状?我没有想清楚.”10 月 31 日,在鲸媒体举办的以“教育 +AI”为的主题 ...

  8. c++编程规范的纲要和记录 (转)

    这是一本好书, 可以让你认清自己对C++的掌握程度. 看完之后,给自己打分,我对C++了解多少? 答案是不足20分. 对于我自己是理所当然的问题, 就不提了, 记一些有启发的条目和细节: (*号表示不 ...

  9. Linux下Tomcat端口、进程以及防火墙设置

     Linux下Tomcat端口.进程以及防火墙设置 1,查看tomcat进程: #ps -aux | grep tomcat(或者ps -ef | grep tomcat都行) 可以看到现在运行着两个 ...

  10. 09: xmltodict 模块将xml格式转成json格式

    1.1 : xmltodict 模块将xml格式转成json格式 <?xml version="1.0"?> <!--#版本号--> <data> ...