zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Ecommerce 3.0雏形出现
    网上购物折扣如此红火
    [ZZ]将测试人员整合到敏捷团队中
    晒工资网——Glassdoor
    [ZZ].NET自动探索式测试工具——Pex
    [ZZ]好的测试应该具备哪些特质?
    我用到的Firefox插件
    [ZZ]WatiN & Selenium RC-自动化测试工具比较
    [ZZ]高盛:Amazon预计10年营收涨10倍达台币3兆元
    从优惠券到维络卡
  • 原文地址:https://www.cnblogs.com/bolderic/p/7156571.html
Copyright © 2011-2022 走看看