zoukankan      html  css  js  c++  java
  • [AtCoder Beginner Contest 165] E

    [AtCoder Beginner Contest 165] E - Rotation Matching (构造)

    Problem Statement

    You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) NN players will participate in this competition, and they are given distinct integers from 11 through NN. The arena has MM playing fields for two players. You need to assign each playing field two distinct integers between 11 and NN (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of NN rounds, each of which proceeds as follows:

    • For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
    • Then, each player adds 11 to its integer. If it becomes N+1N+1, change it to 11.

    You want to ensure that no player fights the same opponent more than once during the NN rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.

    题意:

    大概就是给定一个含有(mathit n)个整数((1,2,3,dots,n-1,n))环,

    让你在其中选择(mathit m)对数字,要求:

    1、 每一个数字最多出现在一个数字对中。

    2、不能有两个数字对,使其在环的2个方向的距离有相等的。

    思路:

    (mathit m)为奇数时:

    (mathit m)为偶数时:

    即:

    我们可以构造((1,m+1),(2,m),...)差为(m,m-2,m-4...)

    ((m+2,2*m+1),(m+3,2*m),...)差为(m-1,m-3...)

    代码:

    	int n = readint();
        int k = readint();
        int base = k;
        int l = 1;
        int r = k + 1;
        while (base--)
        {
            if (l >= r)
            {
                l = k + 2;
                r = 2 * k + 1;
            }
            printf("%d %d
    ", l++, r-- );
        }
    
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    robot framework 初始化清除
    python获取命令行参数
    行业基金
    Ubuntu关闭开机自启项
    ubuntu18.04安装adb
    JavaScript
    centos关闭开机自启项
    CSDN值得学习的专栏
    ubuntu和centos操作命令对比
    linux解压文件命令
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/12833079.html
Copyright © 2011-2022 走看看