首页 > 其他分享 >codeforces round 948(Div2)

codeforces round 948(Div2)

时间:2024-05-28 21:12:01浏览次数:14  
标签:std 948 LL cin long codeforces yes Div2

A题目过简单,略

B.构造+二进制

点击查看代码
#include <bits/stdc++.h>
#define LL long long
LL x, ans[40];
bool yes[40];
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  int T; std::cin >> T;
  while (T --) {
    std::cin >> x;
    for (LL i = 0; i <= 31; ++ i) {
      yes[i] = 0;
      if (x >> i & 1) yes[i] = 1;
    }
    for (LL i = 0; i <= 31; ++ i) ans[i] = 0;
    for (LL i = 0; i <= 31; ++ i) {
      if (yes[i] == 1) {
        int len = 0;
        while (i <= 31 && yes[i] == 1) ++ i, ++ len;
        ans[i - len] = -1, ans[i] = 1;
      }
    }
    for (LL i = 0; i < 31; ++ i) {
      if (ans[i] == -1 && ans[i + 1] == 1) {
        ans[i + 1] = 0, ans[i] = 1;
      }
      if (ans[i] == 1 && ans[i + 1] == -1) {
        ans[i + 1] = 0, ans[i] = -1;
      }
    }
 
    std::cout << 32 << "\n";
    for (int i = 0; i <= 31; ++ i) std::cout << ans[i] << " ";
    std::cout << "\n";
  }
  return 0;
}

标签:std,948,LL,cin,long,codeforces,yes,Div2
From: https://www.cnblogs.com/cici-ruofeng/p/18218910

相关文章

  • Codeforces Round 948 (Div. 2)
    A.LittleNikita题意:\(n\)步操作,\(+1\)或\(-1\),最终结果是否等于\(m\)思路:设\(+1\)的操作次数为\(x\),\(-1\)的操作次数为\(y\)\[x+y=n\\x-y=m\]\[x=(n+m)/2\\y=(n-m)/2\]\((n-m)\)和\((n+m)\)均为偶数,即\(n\)和\(m\)均为偶数或同为奇数,且\(n>=m\)代码:voidsolve()......
  • Codeforces Round 948 (Div. 2) B - C
    总结:做了A,B,然后开局A看错题wa了一发,B出的又很慢,所以掉大分。总的来说还是c没开出来。B.BinaryColouring1.题目大意:给你一个int范围内的数x,要求构造一个二进制串,能有-1、1、0,二进制串的值不能出现两个连续的地方不为0,二进制串的值要等于x。2.思路分析:我们可以发现,对于x的......
  • codeforces round 948(div.2)
    https://m1.codeforces.com/contest/1977A:题意:小男孩尼基塔得到了一些立方体作为礼物。他决定用它们建一座塔。一开始,塔上没有任何立方体。在一次移动中,尼基塔要么正好把1 个立方体放到塔顶,要么正好从塔顶移走1个立方体。有没有可能在走了n 步之后,塔顶正好有m 个立......
  • Codeforces Round 927 (Div. 3) D. Card Game 题解 贪心
    CardGame题目描述Twoplayersareplayinganonlinecardgame.Thegameisplayedusinga32-carddeck.Eachcardhasasuitandarank.Therearefoursuits:clubs,diamonds,hearts,andspades.Wewillencodethemwithcharacters‘C’,‘D’,‘H’,......
  • Codeforces Round #947 题解 (A~G)
    目录A.BazokaandMocha'sArrayB.378QAQandMocha'sArrayC.ChamoandMocha'sArrayD.PainttheTreeE.ChainQueriesF.SetG.ZimphaFanClubA.BazokaandMocha'sArray枚举每个循环移位判断.B.378QAQandMocha'sArray首先最小的数肯定得选,删掉最小的数的倍数......
  • Codeforces Round 947 (Div. 1 + Div. 2) E. Chain Queries
    本来决定开摆养生不打的,但11点半的时候点进去看到这个题是个疑似DS,写题的欲望瞬间高涨,然后就40min写了这个题然而赛中并不能提交,只好等到第二天早上再交一发,没想到还WA了一发才过首先这题如果我们能确定当前黑色点集的链的两个端点\(x,y\)的话,这个题就非常显然了只需要求出\((x......
  • 24.2.13 ~ 4.13 Codeforces Round 925 & 926 & 934 & 939 (Div.3 / Div.2 * 3)
    925Div.3Solve:A~G(7/7)Rank:95Rating:\(0+706=706\)(\(1400+206=1606\))发挥评价:Normal+本场没什么有价值题目。926Div.2Solve:A~DF(5/6)Rank:72Rating:\(706+575=1281\)(\(1606+225=1831\))发挥评价:Good本场没有什么失误。CF1929E*2300(me*2300)选......
  • Codeforces Round 947 (Div. 1 + Div. 2)
    Solve:A~ERank:425Rating:\(1744+195=1939\)(\(1894+95=1989\))发挥评价:Normal本场问题:E先WAon4,较快找出问题后修改WAon27,就又急了(重现上午),开始怀疑做法正确性未果,结果1h后才发现是代码出现问题。注意先检查代码漏洞而不是先怀疑正确性(尤其是错在后面时候,要是正......
  • Codeforces Global Round 12 C2. Errich-Tac-Toe (Hard Version) 题解 构造
    Errich-Tac-Toe(HardVersion)题目描述TheonlydifferencebetweentheeasyandhardversionsisthattokensoftypeOdonotappearintheinputoftheeasyversion.ErrichtogaveMonogonthefollowingchallengeinordertointimidatehimfromtakingh......
  • Codeforces Round 946 (Div. 3) G Money Buys Less Happiness Now(反悔贪心)
    MoneyBuysLessHappinessNow1.题目大意:有n天,每天可以赚x块钱,然后每天可以通过花\(C_{i}\)块钱购买1点快乐值,然后每天赚的钱至少要在下一天才能用,问最多能获得多少快乐值。2.解题思路:我们发现天数变得很多,不能像e题那样dp了,所以要用贪心。具体来讲,我们碰到当前能买的就直接......