当前位置:网站首页>CF1473C No More Inversions
CF1473C No More Inversions
2022-07-30 02:30:00 【秦小咩】
题目描述
You have a sequence aa with nn elements 1, 2, 3, \dots, k - 1, k, k - 1, k - 2, \dots, k - (n - k)1,2,3,…,k−1,k,k−1,k−2,…,k−(n−k) ( k \le n < 2kk≤n<2k ).
Let's call as inversion in aa a pair of indices i < ji<j such that a[i] > a[j]a[i]>a[j] .
Suppose, you have some permutation pp of size kk and you build a sequence bb of size nn in the following manner: b[i] = p[a[i]]b[i]=p[a[i]] .
Your goal is to find such permutation pp that the total number of inversions in bb doesn't exceed the total number of inversions in aa , and bb is lexicographically maximum.
Small reminder: the sequence of kk integers is called a permutation if it contains all integers from 11 to kk exactly once.
Another small reminder: a sequence ss is lexicographically smaller than another sequence tt , if either ss is a prefix of tt , or for the first ii such that s_i \ne t_isi=ti , s_i < t_isi<ti holds (in the first position that these sequences are different, ss has smaller number than tt ).
输入格式
The first line contains a single integer tt ( 1 \le t \le 10001≤t≤1000 ) — the number of test cases.
The first and only line of each test case contains two integers nn and kk ( k \le n < 2kk≤n<2k ; 1 \le k \le 10^51≤k≤105 ) — the length of the sequence aa and its maximum.
It's guaranteed that the total sum of kk over test cases doesn't exceed 10^5105 .
输出格式
For each test case, print kk integers — the permutation pp which maximizes bb lexicographically without increasing the total number of inversions.
It can be proven that pp exists and is unique.
=========================================================================
这种题要是细究原理那就真是摸不着头脑了,直接观察样例
n=k的时候,排列保持不变
n=k+1的时候,顺序排序的后两位被翻转,或者被交换
我们至少是可以猜到,n和k的差值,决定了多少元素被交换或者被翻转。
这里的多少可以是n-k的二倍也可以是n-k+1个元素,我们先一个一个猜测,
手写一个n=k+2的情况, p=1 2 3变成了 3 2 1
看来完全可以确定不是交换,而是n-k+1个元素完全被翻转,不是n-k的二倍个元素,而是n-k+1个元素
也就是说,题目要是多给一个样例这个题连A题都算不上了
# include<bits/stdc++.h>
# define mod 10
using namespace std;
typedef long long int ll;
int main ()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
for(int i=1;i<=k-(n-k)-1;i++)
{
cout<<i<<" ";
}
for(int i=k;i>=k-(n-k);i--)
{
cout<<i<<" ";
}
cout<<'\n';
}
return 0;
}
边栏推荐
- CSDN外链解决方法 (2022-07-28测试可用)
- Typora transparent background image
- Hacker News Broadcast | A fake offer steals $625 million
- Oracle 迁移至Mysql
- matlab洗碗机节水模型的优化设计-这是个课题名称,不是买洗碗机,审核的人仔细看下,谢谢
- consul 操作
- 有一个设计时钟的题目,进行详细分析(三)
- A transaction is in Mysql?What's the use?
- 基于低能耗自适应聚类层次结构(LEACH)(Matlab代码实现)
- LeetCode Question of the Day (874. Walking Robot Simulation)
猜你喜欢
Typora transparent background image
五种绑定彻底弄懂this,默认绑定、隐式绑定、显式绑定、new绑定、箭头函数绑定详解
Is it difficult for AI to land?Cloud native helps enterprises quickly apply machine learning MLOps
JS Navigator appName appVersion userAgent platform
多线程---初阶
基于低能耗自适应聚类层次结构(LEACH)(Matlab代码实现)
CVPR 2022 Best Paper -- Learning to Solve Hard Minimal Problems
JS develops 3D modeling software
戴尔首款纯软产品,再定义下一代对象存储
EL 表达式
随机推荐
浏览器缓存机制
fluttter学习之ButtonStyle 、MaterialStateProperty
consul 操作
STM32L4R9ZIY6PTR STM32L4高性能嵌入式—MCU
快速入门jsp
AI落地难?云原生助力企业快速应用机器学习 MLOps
错误:“filesystem“ 不是 “std“ 的成员
躲避雪糕刺客?通过爬虫爬取雪糕价格
固体火箭发动机三维装药逆向内弹道计算
生死时速,分秒必争
戴尔首款纯软产品,再定义下一代对象存储
Drawing Problem Log
SwiftUI SQLite Database Storage Tutorial Collection (2022 Edition)
【C语言刷LeetCode】592. 分数加减运算(M)
Unity Editor自定义一个记录Bug的窗口
go grpc 自定义拦截器
Zero code tools recommended - HiFlow
力扣刷题训练(二)
【ModelArts系列】华为ModelArts Notebook训练yolov3模型(开发环境)
WebSocket在线通信