首页 > 其他分享 >Codeforces Round #854 by cybercats (Div. 1 + Div. 2) A-B题解

Codeforces Round #854 by cybercats (Div. 1 + Div. 2) A-B题解

时间:2023-02-28 22:59:13浏览次数:56  
标签:854 tmp int 题解 pos cin -- Div hav

比赛链接

A

可以发现,每次出去的顺序一定是按照 \(n -> 1\) 的顺序。因为新加入的东西只会放在最前面。相应的,如果其已在序列中,则这个操作不会对 \(1~n\) 的信息产生影响。
所以只需要统计当前累计出现过多少个不同的新消息即可。

#include <bits/stdc++.h>
using namespace std;
#define N 100010

int n, m; 
map<int, int> ans; 

int main(){
    int T; cin >> T; 
    while(T--){
        ans.clear(); 
        cin >> n >> m; 
        vector <int> G; 
        int now = n; 
        for(int i = 1; i <= m; i++){
            int x; cin >> x; 
            G.push_back(x); 
        }
        bitset <N> vis(0); 
        int num = 0; 
        for(int i = 0; i < G.size(); i++){
            if(!vis[G[i]]){  
                ans[now] = i + 1; 
                vis[G[i]] = 1; 
                now--; 
            }
        }
        for(int i = 1; i <= n; i++){
            printf("%d ", ans[i] == 0 ? -1 : ans[i]); 
        }
        cout << endl; 
    }
    return 0; 
}

B

首先特判,同时含有 \(1\) 和其他数字肯定是不行的。其次,显然,我们不能用小数字除以大数字,这样一定会产生 \(1\)。
那么不妨如此操作:每次将当前最大的数字除以当前最小的数字(动态的),并统计当前最小数字出现的次数。当其出现次数为 \(n\) 时,那么就可以退出了。
(避坑:最小值不一定是 \(2\), 也可以是除到 \(3\) 之类的,因此必须通过出现次数来判断。)

每个数字除最小值显然是不超过 \(log\) 级别的,因此可以在 \(30n\) 次内完成。

···cpp

include <bits/stdc++.h>

using namespace std;

define N 1001

int a[N];
int n;

struct node{
int x;
int pos;

bool operator < (const node &a) const{
    if(x == a.x) return pos < a.pos; 
    else return x > a.x; 
}

} ;

map<int, int> g;

int main(){
int T; cin >> T;
while(T--){
g.clear();
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
bool flag = 0, hav = 0;
bool ok = 1;
for(int i = 1; i <= n; i++){
g[a[i]]++;
if(a[i] == 1) hav = 1;
if(a[i] != 1) flag = 1;
}
for(int i = 2; i <= n; i++)
if(a[i] != a[i-1]) ok = 0;
if(hav && flag){
puts("-1");
continue;
}
else if(hav && !flag){
puts("0");
continue;
}
else if(ok){
puts("0");
continue;
}
set s;
vector <pair<int, int> > G;
for(int i = 1; i <= n; i++)
s.insert((node){a[i], i});
while(233){
auto t = s.end(); t--;
if(g[t->x] == n) break;
auto it = s.begin();
int tmp = it->x;
int pos = it->pos;
G.push_back(make_pair(it->pos, t->pos));
g[tmp]--;
tmp = ceil((double)tmp / (double)t->x);
g[tmp]++;
s.erase(it);
s.insert((node){tmp, pos});
}
printf("%d\n", G.size());
for(auto it : G){
cout << it.first << " " << it.second << endl;
}
}
return 0;
}

标签:854,tmp,int,题解,pos,cin,--,Div,hav
From: https://www.cnblogs.com/wondering-world/p/17166385.html

相关文章

  • Educational Codeforces Round 143 (Rated for Div. 2)(A,C,D)
    EducationalCodeforcesRound143(RatedforDiv.2)(A,C,D)好久没有写题了,这次\(vp\)竟然连\(vs\)都不会用了,O(∩_∩)OAA这个也是差一点了,还有一个情况我的解法是没有......
  • border出现虚边问题解决
    当我们只给元素设置了border-top,没有设置其他边框的时候,如果我们使用了border-radius会出现虚边的情况,如下所示:css代码:div{width:100px;height:100px;border-top:2pxsoli......
  • 跨域问题解决
    目录跨域请求问题解决解决跨域问题方式简单请求与非简单请求自己编写中间件处理跨域请求问题解决同源策略(Sameoriginpolicy)是一种约定,它是浏览器最核心也最基本的安全......
  • Codeforces Round #854 by cybercats (Div. 1+2) 1799 A~G 题解
    点我看题A.RecentActions注意到只有编号大于n的博客会被更新,所以每当有一个之前没被更新的过的博客被更新时,当前列表中最下面的就会被挤掉。如果这次更新的博客之前已......
  • [洛谷]P5401 [CTS2019] 珍珠 题解
    [洛谷]P5401[CTS2019]珍珠题解题意概述有\(D\)种珍珠,每种有无限颗,现在等概率的从\(D\)种珍珠中抽\(n\)次珍珠,每次抽\(1\)个珍珠,记第\(i\)种珍珠最后一共抽......
  • 江南信息学2023年第一周练习20230223 题解
    比赛链接1001:鸡尾酒疗法1#include<bits/stdc++.h>2usingnamespacestd;3intmain()4{5intn;6cin>>n;7doublea,b;8cin>>a......
  • Educational Codeforces Round 112 (Rated for Div
    EducationalCodeforcesRound112(RatedforDiv.2)CodeForces-1555DSayNotoPalindromes如果一个字符串中不包含长度2以上的回文子串,我们就说这个字符串是漂亮......
  • Codeforces Round #776 (Div
    CodeforcesRound#776(Div.3)CodeForces-1650DTwistthePermutation给定你数组a:123...n,一共有n次操作,每次操作可以把\(a_i\)移到最左边,然后对\(i+1\)位以......
  • [CF755G] PolandBall and Many Other Balls 题解
    [CF755G]PolandBallandManyOtherBalls题解题意概括有一排\(n\)个球,定义一个组可以只包含一个球或者包含两个相邻的球。现在一个球只能分到一个组中,求从这些球中......
  • Django uwsgi问题解析
    通常情况下,部署Django应用到生产环境时都会通过uwsgi部署,uwsgi一些配置项配置问题有可能会导致服务出现502状态码或者其他超时等的情况常用到的配置项如下:reload-on-as......