• Codeforces Gym 100187K K. Perpetuum Mobile 构造


    K. Perpetuum Mobile

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/gym/100187/problem/K

    Description

    The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main part is the energy generator which allows the other mobile's parts work. The generator consists of two long parallel plates with n lasers on one of them and n receivers on another. The generator is considered to be working if each laser emits the beam to some receiver such that exactly one beam is emitted to each receiver.

    It is obvious that some beams emitted by distinct lasers can intersect. If two beams intersect each other, one joule of energy is released per second because of the interaction of the beams. So the more beams intersect, the more energy is released. Innokentiy noticed that if the energy generator releases exactly k joules per second, the perpetuum mobile will work up to 10 times longer. The scientist can direct any laser at any receiver, but he hasn't thought of such a construction that will give exactly the required amount of energy yet. You should help the scientist to tune up the generator.

    Input

    The only line contains two integers n and k (1 ≤ n ≤ 200000, ) separated by space — the number of lasers in the energy generator and the power of the generator Innokentiy wants to reach.

    Output

    Output n integers separated by spaces. i-th number should be equal to the number of receiver which the i-th laser should be directed at. Both lasers and receivers are numbered from 1 to n. It is guaranteed that the solution exists. If there are several solutions, you can output any of them.

    Sample Input

    4 5

    Sample Output

    4 2 3 1

    HINT

    题意

    给你n个数,让你构造存在k个逆序数的序列

    题解:

    看是否大于n-1,然后大于n-2,就这样一直找下去就好了

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 200101
    #define mod 1000000009
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    ll n,k;
    
    int kiss[maxn];
    int main()
    {
        n=read(),k=read();
        int step=1;
        int flag=n-1;
        while(flag>=0)
        {
            if(k>=flag)
            {
                k-=flag;
                kiss[flag]=step++;
            }
            flag--;
        }
        for(int i=0;i<n;i++)
        {
            if(kiss[i])
                printf("%d ",kiss[i]);
            else
                printf("%d ",step++);
        }
    }
  • 相关阅读:
    使用强名称为程序集签名
    使用SN.exe对.Net生成的程序集进行签名
    .Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法
    MongoDB查询
    mongo批量写入es
    用 Spark 处理复杂数据类型(Array、Map、JSON字符串等)
    kafka消费者
    kafka生产者
    Pyspark常用API总结
    selenium+chromedriver+python3 不加载图片
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4657731.html
Copyright © 2020-2023  润新知