当前位置: 首页 > news >正文

Codeforces Round #638 (Div. 2) B. Phoenix and Beauty (构造)

传送门


在这里插入图片描述
1.前两天出去玩了,5.1刚回来晚上就打了这场 c f cf cf,三天不做题,如隔千秋。智商都下滑了,这题看懂之后我想写 s t r i n g string string直接构造,但是麻烦的是,肯定会出现数组里的数 x > 10 x>10 x>10,这怎么 s t r i n g string string,我被我自己整吐了

2.正解:我们假设最后得到的序列如下,因为任意 k k k长度的子序列的和都相等,那么我们使用尺取/滑动窗口的思路过一下,不难发现,向右滑动一位后,只有 a [ 1 ] a[1] a[1]被减去,而 a [ k + 1 ] a[k+1] a[k+1]被加上后和不变,意味着什么—— a [ 1 ] = a [ k + 1 ] a[1]=a[k+1] a[1]=a[k+1],同理我们得到每 k k k个数就是一个循环节即可满足题意
在这里插入图片描述
因为题目是在添加的基础上,因此我们首先得到不无重复元素顺序按输入出现的子序列,如果整个初始序列的种类大于了 k k k显然无法构造。如果可以,先将刚刚生成的子序列长度添加为 k k k,接着对原序列的每个数都输出这样一个序列,长度为 n ∗ k n*k nk

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;

int a[maxn];
unordered_map<int,int> mp;

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t,n,k;
    cin>>t;
    while(t--){
        cin>>n>>k;
        int sum=0;
        mp.clear();
        vector<int> ans;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(!mp[a[i]]){
                sum++;
                mp[a[i]]=1;
                ans.push_back(a[i]);
            }
        }
        if(sum>k){
            cout<<"-1"<<endl;;
            continue;
        }
        for(int i=1;i<=n;i++)
            if(!mp[i] && sum<k){
                ans.push_back(i);
                sum++;
            }
        cout<<k*n<<endl;
        for(int i=0;i<n*k-1;i++){
            cout<<ans[i%k]<<' ';
        }
        cout<<ans[k-1]<<endl;
    }
    return 0;
}




相关文章:

  • Codeforces Round #638 (Div. 2) C Phoenix and Distribution(思维/构造)
  • Mac Application GDB Usage
  • “Shopee杯“e起来编程暨武汉大学2020年大学生程序设计大赛决赛
  • iPhone开发秘籍一书中的翻译错误
  • 2020WHU校赛 I - Interesting Matrix Problem(规律+整除分块)
  • UVA1025 A Spy in the Metro (dp)
  • 欢迎大家来这里学习
  • UVA437 The Tower of Babylon(记忆化搜索)
  • MySQL启多个实例
  • UVA116 Unidirectional TSP(dp/多段图的最短路)
  • 忍受未知很重要
  • 背包九讲(1)——01背包
  • 两大重要活动议程
  • 背包九讲(2)——完全背包
  • Winforms: 把Label显示为多行
  • php的引用
  • echarts花样作死的坑
  • es6(二):字符串的扩展
  • Laravel 菜鸟晋级之路
  • mysql_config not found
  • SSH 免密登录
  • windows下mongoDB的环境配置
  • 表单中readonly的input等标签,禁止光标进入(focus)的几种方式
  • 欢迎参加第二届中国游戏开发者大会
  • 力扣(LeetCode)56
  • 每个JavaScript开发人员应阅读的书【1】 - JavaScript: The Good Parts
  • 深度学习入门:10门免费线上课程推荐
  • 使用前端开发工具包WijmoJS - 创建自定义DropDownTree控件(包含源代码)
  • 写给高年级小学生看的《Bash 指南》
  • 新版博客前端前瞻
  • 用Python写一份独特的元宵节祝福
  • 运行时添加log4j2的appender
  • 7行Python代码的人脸识别
  • puppet连载22:define用法
  • 完善智慧办公建设,小熊U租获京东数千万元A+轮融资 ...
  • ​低代码平台的核心价值与优势
  • # 执行时间 统计mysql_一文说尽 MySQL 优化原理
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • $Django python中使用redis, django中使用(封装了),redis开启事务(管道)
  • (4.10~4.16)
  • (LeetCode 49)Anagrams
  • (pojstep1.1.2)2654(直叙式模拟)
  • (附源码)springboot宠物管理系统 毕业设计 121654
  • (牛客腾讯思维编程题)编码编码分组打印下标(java 版本+ C版本)
  • (四)JPA - JQPL 实现增删改查
  • (转) Android中ViewStub组件使用
  • (转)【Hibernate总结系列】使用举例
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • (转)关于pipe()的详细解析
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • ***汇编语言 实验16 编写包含多个功能子程序的中断例程
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .Net 4.0并行库实用性演练
  • .NET Framework 服务实现监控可观测性最佳实践
  • .net 流——流的类型体系简单介绍