首页 > 其他分享 >Codeforces Round 838 (Div. 2)

Codeforces Round 838 (Div. 2)

时间:2022-12-16 22:25:04浏览次数:39  
标签:tar 底基 int 838 Codeforces Div op 整除 first

B. Make Array Good

题意:

给定n个数,每次可以对其中一个数进行操作 ,其中 ,在操作数量不超过n的前提下,构造一种操作使得任意两个数中,大的数可以被小的数整除。

分析:

结论:所有数共享了同一个底基,即被同一个数整除,那么要让这些数都能互相整除的条件是:他们是底基的倍数,倍数为2的整次幂。

以最小的数为底基,对于每一个数可以构造出相对应的倍数为2的整次幂的数。

#include<bits/stdc++.h>
using namespace std;
const int N=100010;
typedef long long ll;
pair<ll,int> a[N];
int main()
{
    int op,n;cin>>op;
    while(op--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
       {
            cin>>a[i].first;
            a[i].second=i+1;
       }
       sort(a,a+n);

        ll tar=a[0].first,cnt=0;

        for(int i=0;i<n;i++)
        {
            while(a[i].first>tar) tar*=2;
            a[i].first=tar-a[i].first;
            if(a[i].first) cnt++;
        }
        cout<<cnt<<endl;
        for(int i=0;i<n;i++)
        {
            if(a[i].first)
                cout<<a[i].second<<' '<<a[i].first<<endl;
        }
    }
    
    return 0;
}

标签:tar,底基,int,838,Codeforces,Div,op,整除,first
From: https://www.cnblogs.com/Szang/p/16988395.html

相关文章

  • 「Editorial」Codeforces Contest 1149
    C.TreeGenerator™容易发现树上一条路径一定形如))...)((...(。也就是对于任意子段,去掉匹配了的括号后还剩下的部分。而这个东西还是不太好表示,我们有如下引理:这个值......
  • Codeforces Round #837 (Div. 2)
    A.HossamandCombinatorics(CF1771A)题目大意给定一个长度为\(n\)的数组\(a\),问有多少个数对其差的绝对值等于该数组的极差。解题思路若最大值和最小值相等,则答案......
  • div的使用
    div:盒子模型(块级元素)border:边框总写:border-color:边框颜色例:(顺时针顺序+对称原则)border-color:redblueyellowpink;分写:border-top-color:上边框颜色......
  • Codeforces Round #838 (Div. 2) D
    D.JourneytoUn'Goro题链考虑一个三元组内一定可以排除一个非0的xyz我们询问xz和yz要是gx==gy那么我们的z一定不是0否则gx=pxgy=py排除z要是gx!=gy那么......
  • Educational Codeforces Round 2
    EducationalCodeforcesRound2https://codeforces.com/contest/6003/6:ABDA.ExtractNumbers小模拟。把一个字符分成两部分输出,遇到';'或','视为单词分隔符,非负......
  • Codeforces Round #838 (Div. 2) D. GCD Queries
    题意有个长度为n的排列p,[0,1,2,...n-1],你可以进行至多2*n次询问,每次询问两个i,j,返回gcd(pi,pj),让你在规定时间内猜出0在哪两个位置之一思路这是一道交互题,询问的上限是2n......
  • Educational Codeforces Round 139 (Rated for Div. 2)
    EducationalCodeforcesRound139(RatedforDiv.2)数组开小,身败名裂场。CF1766AExtremelyRound直接前缀和递推预处理一下每个\(n\)的答案,询问直接输出即可。CF......
  • 一个新ACMer的刷题记录捏(Round.694) codeforces ABC
    A.StrangePartitionProblem-A-Codeforces  2022-12-1514:00:52​#include<bits/stdc++.h>#defineintlonglongconstintN=100010;usingnamespac......
  • div 常用样式记录
    div边框:  boder虚线:dashed 实线:solid  语法:<divstyle="border:2pxsolidred"></div>  上边框:border-top;下边框:border-bottom;左边框:border-left;右边框......
  • Educational Codeforces Round 136 (Rated for Div. 2)
    题目链接A核心思路:其实就是一个签到题没什么好说的,我们可以直接通过观察样例大胆猜测结论:也就是只有是一列的时候是完全孤立的。直接看代码吧.#include<bits/stdc++.h>......