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..............下去

代码

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define MOD 1000000007
#define maxn 32001
using namespace std;
typedef __int64 ll;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//*******************************************************************
ll a[];
ll q[];
int main()
{
ll n;
ll k;
n=read(),k=read();
for(ll i=; i<=n; i++)
a[i]=i;
if(k==)
{
for(ll i=; i<=n; i++)
printf("%I64d ",a[i]);
return ;
}
ll j=;
ll x=;
ll kk=;
ll nn=n;
while(k)
{
if(k>=n-j)
{
q[++x]=a[nn];
nn--;
k=k-(n-j);
}
else
{
q[++x]=a[kk];
kk++;
}
j++;
}
j--;
for(ll i=; i<=x; i++)
{
printf("%I64d ",q[i]);
}
for(ll i=kk; i<nn+; i++)
printf("%I64d ",a[i]);
return ;
}
 

Codeforces Gym 100187K K. Perpetuum Mobile 构造的更多相关文章

  1. K. Perpetuum Mobile

    The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main par ...

  2. codeforces gym 100971 K Palindromization 思路

    题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...

  3. Codeforces Gym 100425H H - Football Bets 构造

    H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  4. Codeforces Gym 100523K K - Cross Spider 计算几何,判断是否n点共面

    K - Cross SpiderTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  5. codeforces gym 100357 K (表达式 模拟)

    题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...

  6. codeforces gym 101164 K Cutting 字符串hash

    题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...

  7. Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )

    题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

随机推荐

  1. 转:Java NIO系列教程(三) Buffer

    Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...

  2. 利用nginx向现有网站添加登录验证功能(不添加修改现有网站代码)

    在不改变现有网站代码的前提下加入验证功能: 1.假设现有网站后端nodejs,端口3000,nginx配置如下 server { listen 80; server_name localhost; l ...

  3. javascript单体模式

    单体模式的思想在于保证一个特定类仅有一个实例.这意味着当第二次使用同一个类创建的新对象的时候,应该得到与第一个所创建的对象完全相同. javacript中并没有类,因此对单体咬文嚼字的定义严格来说并没 ...

  4. 完美串(区间dp)

    完美串 Description 爱美之心人皆有之,GG也不例外.所以GG他对于完美串有一种热衷的爱.在GG眼中完美串是一个具有无比魅力的01子串.这个子串有之其魅力之处,对它取反后水平翻转,它又和它原 ...

  5. 2维特征Feature2D(转)

    转自:http://blog.csdn.net/yang_xian521/article/details/6901762 主要介绍的是如何用SURF进行特征匹配,和SIFT的使用方法基本一致.

  6. TCP/IP协议原理【转载】

    前述        各种L2数据网具有不同的通信协议与帧结构,其网络节点设备可以是各种类型的数据交换机(X.25.FR.Ethernet和ATM等分组交换机):而L3数据网(IP网或internet) ...

  7. Linux MySQL差异备份技巧

    MSSQL差异备份使用技巧 15 Apr 2013 所谓的差异备份,就是只备份最近一次备份之后到此次备份之前所增加的那一部分数据.打个比方我第N次备份后数据库存放的内容是ABCD,然后我第N+1次 备 ...

  8. java前三本基础知识总结

    基础软件:1:JDK,JRE,JVM(一些参数和作用),GC(机制和算法),Class,Loader(机种作用,加载顺序) 2:环境搭建:JAVA_HOME,path,class 语言基础:引用类型: ...

  9. 使用msgfmt编译多语言文件

    msgfmt --statistics --verbose -o django.mo django.po

  10. 排序稳定性stable

    stable排序 O(n^2): InsertionSort,BubbleSort O(nlgn): MergeSort O(n+k): CountSort, RadixSort,BucketSort ...