博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
比赛F-F Perpetuum Mobile
阅读量:7116 次
发布时间:2019-06-28

本文共 2437 字,大约阅读时间需要 8 分钟。

比赛F-F     Perpetuum Mobile

 

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

 

题目:

Description

standard input/output

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
2 #include
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

你可能感兴趣的文章
Ionic Cordova实现软键盘的监听 以及操作大全
查看>>
Android小知识10则(下)
查看>>
Flask源码解析:从第一个版本开始阅读Flask源码
查看>>
JavaScript 工作原理之二-如何在 V8 引擎中书写最优代码的 5 条小技巧(译)
查看>>
Java集合(一) —— ArrayList
查看>>
作为JavaScript开发人员,这些必备的VS Code插件你都用过吗
查看>>
Promise 学习笔记
查看>>
区块链招聘面试工作中可能会问到的40个问题。
查看>>
[译] 如何在安卓应用中使用 TensorFlow Mobile
查看>>
SEO优化之——html页面相关总结
查看>>
一个不太好的消息
查看>>
Node.js 非阻塞的 Sleep 要怎么写 ?
查看>>
Python基础(十八): 类和对象以及它们的属性
查看>>
java B2B2C Springcloud仿淘宝电子商城系统
查看>>
【动画】当我们在读写Socket时,我们究竟在读写什么?
查看>>
Android Studio 修改包名 com.example.calculator-----&gt;com.melon.calculator
查看>>
SpringBoot Cache 深入
查看>>
解决POI大数据导出Excel内存溢出、应用假死
查看>>
AI考拉技术分享会--IDE 常用功能 for Node.js
查看>>
vue常见知识点总结
查看>>