首页 > 其他分享 >2022-11-08个人周赛

2022-11-08个人周赛

时间:2022-11-11 00:44:55浏览次数:66  
标签:11 周赛 const cout int 08 var ll define

B. Jamie and Binary Sequence (changed after round)

y最小,字典序最大

先按二进制分解,最大的为2x。如果全都拆成2x-1,拆完之后总个数还比k小,就拆,不然就拆最小的

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define rep(a, b, c) for(int (a)=(b);(a)<=(c);(a)++)
#define per(a, b, c) for(int (a)=(b);(a)>=(c);(a)--)
#define mset(var, val) memset(var,val,sizeof(var))
#define ll long long
#define int ll
#define fi first
#define se second
#define no "No\n"
#define yes "Yes\n"
#define eb emplace_back
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>

const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);

priority_queue<int>q;
priority_queue<int,vector<int>,greater<int> >p;

map<int,int>mp;

void solve() {
    int n,k,mx=-100;
    cin>>n>>k;
    per(i,62,0){
        if(n&(1ll<<i)){
            q.push(i);
            mp[i]++;
            if(mp[i])    mx=max(mx,i);
        }
    }
    if(q.size()>k){
        cout<<no;
        return;
    }
    int len=k-q.size();
    while(mp[mx]<=len){
        int tx=q.top();
        len=len-mp[mx];
        while(1){
            int x=q.top();
            if(x!=tx) {
                mp[mx-1]=mp[mx-1]+mp[mx]*2;
                mp[mx]=0;
                mx=mx-1;
                break;
            }
            q.pop();
            q.push(x-1);
            q.push(x-1);
        }
    }
    while(!q.empty()){
        p.push(q.top());
        q.pop();
    }
    for (int i = 0; i < len; ++i) {
        int x=p.top();
        p.pop();
        p.push(x-1);
        p.push(x-1);
    }
    while(!p.empty()){
        q.push(p.top());
        p.pop();
    }
    cout<<yes;
    while(!q.empty()){
        cout<<q.top()<<" ";
        q.pop();
    }
    cout<<endl;
}

signed main() {
    IOS;
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

标签:11,周赛,const,cout,int,08,var,ll,define
From: https://www.cnblogs.com/ShG-V/p/16879342.html

相关文章

  • 208.实现Trie(前缀树)
    Trie(发音类似"try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。请你实现Tri......
  • GL-Polite Behavior 20221101
    PolitebehaviorTime2022.11.01Tuesday23:00-23:45Whenitcomestomannersandetiquette,everycountryseemstohaveitsownsetofrules.Discusswhatis......
  • C++ 11新特性:类模板 ----- 元组tuple
    C++11标准新引入了一种类模板,命名为tuple(中文可直译为元组)。tuple最大的特点是:实例化的对象可以存储任意数量、任意类型的数据。tuple的应用场景很广泛,例如当需要存储......
  • MIT6.S081笔记:Lab Xv6 And Unix Utilities
    关于MIT6.S081这门课的前身是MIT著名的课程6.828,MIT的几位教授为了这门课曾专门开发了一个基于x86的教学用操作系统JOS,被众多名校作为自己的操统课程实验。但随......
  • Java学习——11.10
    今天得时间都花在数学和英语上了,Java的话就只看了一点对象和内存的关系,但我觉得够了。这章虽然狂神讲的很浅,又因我没怎么学过数据结构,于是我又从CSDN上看了点。下面来......
  • 【2022.11.10】luffy项目部署(6)
    内容概要1.首页中间部分样式2.多方式登录接口2.1视图类2.2序列化类2.3路由3.手机号是否存在接口3.1视图类4.腾讯云短信介绍和申请4.1什么是api,什么是sd......
  • 第六章11
    【题目描述】有一个m行n列的矩阵,编程求出其中值最大的那个元素,以及其所在的行号和列号。(如果最大数有多个,则显示第一个出现的数据的信息)。【输入】有多行。第1行是两个......
  • 2022-11-10学习内容
    1.案例-购物车-加入购物车1.1ShoppingChannelActivity.javapackagecom.example.chapter06;importandroidx.appcompat.app.AppCompatActivity;importandroid.net.......
  • LeetCode刷题记录.Day11
    赎金信题目链接代码随想录(programmercarl.com)classSolution{public:boolcanConstruct(stringransomNote,stringmagazine){intrecord[26]={......
  • 【2022-11-06】牛杂记
    20:00人不管走到哪一步,总得找点乐子,想一点办法,老是愁眉苦脸,干吗呢!                                ......