zoukankan      html  css  js  c++  java
  • Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile

    Time Limit: 2 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..............下去

    代码

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <ctime>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <set>
     8 #include <vector>
     9 #include <queue>
    10 #include <map>
    11 #include <stack>
    12 #define MOD 1000000007
    13 #define maxn 32001
    14 using namespace std;
    15 typedef __int64 ll;
    16 inline ll read()
    17 {
    18     ll x=0,f=1;char ch=getchar();
    19     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    20     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    21     return x*f;
    22 }
    23 //*******************************************************************
    24 ll a[200101];
    25 ll q[200101];
    26 int main()
    27 {
    28     ll n;
    29     ll k;
    30     n=read(),k=read();
    31     for(ll i=1; i<=n; i++)
    32         a[i]=i;
    33     if(k==0)
    34     {
    35         for(ll i=1; i<=n; i++)
    36             printf("%I64d ",a[i]);
    37         return 0;
    38     }
    39     ll j=1;
    40     ll x=0;
    41     ll kk=1;
    42     ll nn=n;
    43     while(k)
    44     {
    45         if(k>=n-j)
    46         {
    47             q[++x]=a[nn];
    48             nn--;
    49             k=k-(n-j);
    50         }
    51         else
    52         {
    53             q[++x]=a[kk];
    54             kk++;
    55         }
    56         j++;
    57     }
    58     j--;
    59     for(ll i=1; i<=x; i++)
    60     {
    61         printf("%I64d ",q[i]);
    62     }
    63     for(ll i=kk; i<nn+1; i++)
    64         printf("%I64d ",a[i]);
    65     return 0;
    66 }
     
  • 相关阅读:
    java图书管理系统界面版本+mysql数据库
    java数组实现的超市管理系统(控制台)
    Action<T>和Func<T>委托事例
    简单的委托示例
    使用静态方法CreateInstance()创建数组
    Span复习
    与预定义类型的用户类型强制转换
    实现自定义的索引运算符
    比较运算符的重载
    算术运算符的重载
  • 原文地址:https://www.cnblogs.com/zxhl/p/4658003.html
Copyright © 2011-2022 走看看