首页 > 其他分享 >Codeforces Round 979 (Div. 2) B. Minimise Oneness

Codeforces Round 979 (Div. 2) B. Minimise Oneness

时间:2024-10-20 20:47:14浏览次数:3  
标签:全为 int Codeforces 979 cin Oneness ans 序列 define

题目链接:题目

大意:

构造长度为 n n n的01字符串,使得全为零的子序列和至少有一个1的子序列的数量之差的绝对值最小。

思路:

很明显,所有子序列中不是全为0就是至少有一个1,所以算出子序列总数,再让全为0的子序列数量接近它的一半。子序列不要求相邻,只要求相对位置不变,而在这个题目中又只需要考虑0,那么只用看0的个数。
由杨辉三角发现,长度为 n n n的子序列总数就是第 n n n层杨辉三角之和减一,而长度加一,子序列总数至少翻倍,所以0的个数为n-1就行了。

代码:

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

#define int long long
#define MOD 1000000007
#define fi first
#define se second
#define pii pair<int, int>
#define vec vector

void solve(){   
    int n;
    cin >> n;
    string ans;
    for(int i = 0; i < n - 1; i++){
        ans.push_back('0');
    }
    ans.push_back('1');
    cout << ans << '\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}   

标签:全为,int,Codeforces,979,cin,Oneness,ans,序列,define
From: https://blog.csdn.net/puzhaoyu/article/details/143097613

相关文章

  • Codeforces Round 980 (Div. 2)
    糖丸了,什么沟史比赛A.ProfitableInterestRate初始有\(a\)个硬币,可以花费硬币开通盈利账户与非盈利账户开通盈利账户需要至少花费\(b\)个金币开通非盈利账户没有限制每在非盈利账户花费\(x\)元,盈利账户的限制\(b\)就减少\(2x\)元求最大的在盈利账户上的花......
  • Codeforces Round 977 (Div. 2)
    一万一参赛,赛时排名151A.MeaningMean简单贪心题。显然,排在越后面的数,除以2的次数越少。因此贪心地从小到大计算结果即为答案。#include<bits/stdc++.h>usingnamespacestd;constintN=55;intT,n,a[N];intmain(){ scanf("%d",&T); while(T--){ scanf......
  • Codeforces Round 977 (Div. 2, based on COMPFEST 16 - Final Round) A-C1
    ​A.MeaningMean2024.10.17算法:模拟,贪心思路:居然时没看题解直接做出来的T^T贪心:题目要求最后剩下的一个数,使得最大那么我们从这个最大的最后一个数思考,最后一个数肯定时由最后两个数进行相加,再除以2,同时上下取整而得到的。方便陈述,我们设最大的最后一个数,也就是最终答案......
  • 【并查集+dfs】codeforces 1833 E. Round Dance
    题意输入一个正整数\(T(1\leqT\leq10^4)\),表示接下来输入\(T\)组测试用例,对于每一个测试用例:第一行,输入一个正整数\(n(2\leqn\leq2*10^5)\)第二行,输入\(n\)个正整数\(a_i(1\leqa_i\leqn)\),表示节点\(i\)到节点\(a_i\)存在一条有向边,保证无自环这\(n......
  • Educational Codeforces Round 166 (Rated for Div. 2) - VP记录
    比赛链接A.VerifyPassword挨个判断即可,秒了。#include<cstdio>#include<cstring>usingnamespacestd;constintN=25;intT,n;charstr[N];boolis_digit(charch){returnch>='0'&&ch<='9';}boolis_lowercase(charch){re......
  • Codeforces Round 892 (Div. 2)题解记录
    题目链接:https://codeforces.com/contest/1859A.UnitedWeStand选最大的数即可注意题目输出格式 #include<iostream> #include<string.h> #include<map> #include<vector> #include<set> #include<unordered_set> #include<stack> #incl......
  • Codeforces Round 893 (Div. 2)题解记录
    题目链接:https://codeforces.com/contest/1858A.Buttons从自身角度出发,我想赢就得保证我的按钮尽可能多所以,大家都优先按\(c\),然后分析先后顺序即可 #include<iostream> #include<string.h> #include<map> #include<vector> #include<set> #include<unordered_set> #......
  • Codeforces Round 924 (Div. 2) D. Lonely Mountain Dungeons(推式子,思维,差分,前缀和)
    题目链接CodeforcesRound924(Div.2)D.LonelyMountainDungeons思路令f(n,m......
  • Codeforces Beta Round 93 (Div. 1 Only) B. Password 一题三吃
    https://codeforces.com/problemset/problem/126/B学完Z函数,先用哈希做了一遍,再用Z函数做了一遍,然后搜其他人的题解发现用next数组也能做,就又做了一遍B.Password题意给一串字符串\(s\),要求找一个最长的\(t\)\(t\)既是\(s\)的前缀串,也是后缀串,还是除了前缀后缀外的一个......
  • 浏览器安装 AtCoder Better 和 Codeforces Better 插件
    你首先需要篡改猴。如果你用的Google浏览器,请用这个Link,不过你可能需要挂个梯子。如果你用的Firefox浏览器,请用这个Link,这个不需要梯子。如果你用的edge浏览器,请用这个Link,这个也不需要梯子。下载好篡改猴之后,无论什么浏览器,点击这个链接,安装AtCoderBetter插件;点......