• CFRound423_Div2 D High Load


    题目链接:http://codeforces.com/contest/828/problem/D

    必须是一棵树!大体思路就是按照画同心圆的方法给排列出来,一号作为圆心一层一层向外扩展。

    证明的话还得想想。。。

    代码:

     1 int n, k;
     2 
     3 int main(){
     4     scanf("%d %d", &n, &k);
     5     int t = (n - 1) / k - 1, x = (n - 1) % k;
     6     int ans = 0;
     7     if(x == 0) ans = 2 * t + 2;
     8     else if(x == 1) ans = 2 * t + 3;
     9     else ans = 2 * t + 4;
    10     printf("%d
    ", ans);
    11     
    12     for(int i = 1; i <= k; i++){
    13         printf("1 %d
    ", i + 1);
    14     }
    15     for(int i = 2; i <= n - k; i++){
    16         printf("%d %d
    ", i, i + k);
    17     }
    18     
    19 }

    题目:

    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.

  • 相关阅读:
    windows下Mysql免安装版,修改my_default.ini配置文件无效的解决办法
    下压桟(LIFO)
    Dijkstra的双栈算术表达式求值算法
    获取中文的完整拼音并输出
    解析一个文件夹所有文件的中文,并输出到某一文本文档中
    在含有中英文字符串的信息中,提出中文的方法
    创建计算字段
    Docker 常用命令
    mqtt常用命令及配置
    LOG4J
  • 原文地址:https://www.cnblogs.com/bolderic/p/7156571.html
Copyright © 2020-2023  润新知