当前位置:网站首页>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;
}边栏推荐
- nrm ls 为什么前面不带 *了
- 成功解决AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- Detailed explanation of carousel picture 2 - carousel pictures through left positioning
- Leetcode.234 判断回文链表(双指针/快慢指针)
- ESP8266 +0.96“ I2C OLED 表盘时钟
- STM32L4R9ZIY6PTR STM32L4高性能嵌入式—MCU
- 【2023海康威视提前批笔试题】~ 题目及参考答案
- 再度入围|“国产化”大潮来袭,汉得助力乘风破浪!
- 【服务器存储数据恢复】华为OceanStor某型号存储raid5数据恢复案例
- JS history.back() go(-1) Location 跳转 重新加载页面 get请求 返回顶部 bom
猜你喜欢

DAP数据加工流程梳理

JS Navigator appName appVersion userAgent platform

Fudan-Washington University EMBA Kechuang's Ao E丨The Magical Materials and We Are Shaped

FL Studio官方20.9中文版无需汉化补丁,正确安装并设置切换

新型海上风电机组及压缩空气储能系统的建模与控制(Matlab代码实现)

一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?

Tibetan Mapping

centOS安装MySQL详解

Is it difficult for AI to land?Cloud native helps enterprises quickly apply machine learning MLOps

记一次搭建conda虚拟环境
随机推荐
go 双向流模式
可惜了!规模这么大的上市公司说散就散了
uni-app如何配置APP自定义顶部标题栏
菜刀、冰蝎、蚁剑、哥斯拉的流量特征
解决:npm ERR code ELIFECYCLE npm ERR errno 1(安装脚手架过程中,在npm run dev 时发生错误)
The box office broke 790 million US dollars. Have you watched this recent dinosaur movie?
再度入围|“国产化”大潮来袭,汉得助力乘风破浪!
VLAN 实验
基于蒙特卡诺的风场景模型出力(Matlab代码实现)
Docker一键安装MySQL
matlab洗碗机节水模型的优化设计-这是个课题名称,不是买洗碗机,审核的人仔细看下,谢谢
ROS2知识:编译系统ament_cmake
AI落地难?云原生助力企业快速应用机器学习 MLOps
consul 操作
LeetCode 2342. Digital and equal number of one of the biggest and
Oracle 迁移至Mysql
English grammar_indefinite pronouns -some & any
【笔记】结巴分词绘制词云图
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
JS Bom location 楼层导航效果 offsetTop data-n 方括号选择器