比赛F-F Perpetuum Mobile

比赛F-F     Perpetuum Mobile

 

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/F

 

题目:

Description

standard input/output Statements

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

 
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

 

题意: 

已知逆序数为k 的序列,求可能序列的情况(只需输出一种即可)。

 

分析:

观察输入输出可以发现K恰好等于输出序列的逆序数

 

代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n;
 8     long long k;
 9     while(scanf("%d%I64d",&n,&k)!=EOF)
10     {
11         int p=1,q=n;
12         for(int i=1;i<=n;i++)
13         {
14             if(k>=n-i) //从n开始输出
15             {
16                 printf("%d ",q--);
17                 k-=n-i;
18             }
19             else  //不存在逆序数按正序输出
20             {
21                 printf("%d ",p++);
22             }
23         }
24         printf("\n");
25     }
26     return 0;
27 }

比赛的时候没有看懂输入输出的关系,听了汇报之后就明白了。

转载于:https://www.cnblogs.com/ttmj865/p/4721322.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值