比賽F-F Perpetuum Mobileios
題目連接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/Fide
題目:ui
Descriptionspa
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.code
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.orm
Inputblog
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.ip
Outputci
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.get
Sample Input
4 5
4 2 3 1
5 7
4 2 5 3 1
6 0
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 }
比賽的時候沒有看懂輸入輸出的關係,聽了彙報以後就明白了。