zoukankan      html  css  js  c++  java
  • K. Perpetuum Mobile

    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 test(s)
    input
    4 5
    output
    4 2 3 1
    input
    5 7
    output
    4 2 5 3 1
    input
    6 0
    output
    1 2 3 4 5 6

    其实就是 求n的序列 的逆序对数为k;代码比较简单只是难以想到
    #include<iostream>
    using namespace std;
    int main(){
        int n;long long int k;
        while(cin>>n>>k){
               int flag=n,t=1;
            for(int i=1;i<=n;i++){
                if(k>=n-i){
                    k-=n-i;
                    cout<<flag--<<" ";
                }else{
                    cout<<t++<<" ";
                }
            }
            cout<<endl;
        }
    return 0;
    }
    View Code
  • 相关阅读:
    Failed to load config "react-app" to extend from.
    An unexpected error occurred: "expected workspace package to exist for "@babel/core"".
    写一个 LRU 缓存函数(#146)
    TERSUS笔记303-06末页
    TERSUS笔记302-08每页条数逻辑
    TERSUS笔记301-显示列表处理+序号+01共几条取值+08每页条数下拉菜单值设置+02共页数计算取值
    TERSUS笔记300-增加
    TERSUS笔记118-多表增删改查完整操作
    Java多线程之二(Synchronized)
    HashMap在JDK1.7中可能出现的并发问题
  • 原文地址:https://www.cnblogs.com/demodemo/p/4716150.html
Copyright © 2011-2022 走看看