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..............下去
代码
#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 构造的更多相关文章
- K. Perpetuum Mobile
The world famous scientist Innokentiy almost finished the creation of perpetuum mobile. Its main par ...
- codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...
- Codeforces Gym 100425H H - Football Bets 构造
H - Football BetsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 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 ...
- codeforces gym 100357 K (表达式 模拟)
题目大意 将一个含有+,-,^,()的表达式按照运算顺序转换成树状的形式. 解题分析 用递归的方式来处理表达式,首先直接去掉两边的括号(如果不止一对全部去光),然后找出不在括号内且优先级最低的符号.如 ...
- codeforces gym 101164 K Cutting 字符串hash
题意:给你两个字符串a,b,不区分大小写,将b分成三段,重新拼接,问是否能得到A: 思路:暴力枚举两个断点,然后check的时候需要字符串hash,O(1)复杂度N*N: 题目链接:传送门 #prag ...
- Codeforces Gym 100851 K King's Inspection ( 哈密顿回路 && 模拟 )
题目链接 题意 : 给出 N 个点(最多 1e6 )和 M 条边 (最多 N + 20 条 )要你输出一条从 1 开始回到 1 的哈密顿回路路径,不存在则输出 " There is no r ...
- 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 ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
随机推荐
- 一步一步教你如何在linux下配置apache+tomcat(转)
一步一步教你如何在linux下配置apache+tomcat 一.安装前准备. 1. 所有组件都安装到/usr/local/e789目录下 2. 解压缩命令:tar —vxzf 文件名(. ...
- angular-ngSanitize模块-linky过滤器详解
本篇主要讲解angular中的linky这个过滤器.此过滤器依赖于ngSanitize模块. linky能找出文本中的链接,然后把它转换成html链接.什么意思,就是说,一段文本里有一个链接,但是这个 ...
- 开启Mysql远程访问的所有方法
开启Mysql远程访问的所有方法 http://superyjcqw.blog.163.com/blog/static/16105830520117111040436/ Mysql默认是不可以通过远程 ...
- 用JSON-server模拟REST API(一) 安装运行
用JSON-server模拟REST API(一) 安装运行 在开发过程中,前后端不论是否分离,接口多半是滞后于页面开发的.所以建立一个REST风格的API接口,给前端页面提供虚拟的数据,是非常有必要 ...
- linux下Nginx服务器安装教程
序:Nginx服务器安装总结而已,不是教程. 安装的过程中出现了一些问题,原因我的云主机是纯净版,所以很多依赖包都没有.其中安装过程中就发现perl库缺少和openssl库缺少,因此我手动安装的这两款 ...
- A+B Again(在某个数中找大于m的最小约数)
A+B Again Accepted : 15 Submit : 243 Time Limit : 1000 MS Memory Limit : 65536 KB 题目描述 上次趣味赛小明的 ...
- PHP导出数据到CSV文件函数/方法
如果不清楚什么是CSV文件,可看如下文章介绍 CSV格式的是什么文件?CSV是什么的缩写? /** * 导出数据到CSV文件 * @param array $data 数据 * @param arr ...
- PHP5 Session 使用详解(一)
http协议是WEB服务器与客户端(浏览器)相互通信的协议,它是一种无状态协议.所谓无 状态,指的是不会维护http请求数据,http请求是独立的,不持久的.而越来越复杂的WEB应用,需要保存一些用户 ...
- 暑假热身 B. 下载测速
最近,nono终于结束了每年一次的为期12个月的冬眠,醒来的第一件事就是——看电影!!nono发现最近一年出现了各种很好很强大的电影,例如这个.这个.还有这个. 于是nono直接把这些电影全部扔进了下 ...
- HDU2546(01背包饭卡)
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...