D. Playoff

传送门

题意:有2的n次方个数代表2的n次方个队伍,每个队伍的力量值为从1到2的n次方的一个排列,现在给你一个长度为n的字符串,1代表这一局力量值高的队伍获胜,0代表力量值低的队伍获胜。每一次比赛两两队伍比赛,根据字符串来判断有多少力量值可以获胜。

思路:相当于找1和0的数量l,r,边界就是pow(2,l)和pow(2,n)-pow(2.r)+1,然后n为1的时候特判一下就可以了


#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
char s[N];

void solve()
{
	cin>>n;
	cin>>s+1;

	ll l=0,r=0;
	for(int i =1;i<=n;i++)
	{
		if(s[i]=='1')l++;
		else r++;
	}

	if(n==1)
	{
		if(s[1]=='0')
		cout<<1<<endl;
		else 
		cout<<2<<endl;
		return ;
	}
	// cout<<(pow(n,2))<<endl;
	if(l==0)
	cout<<1<<" ";		
	else if(r==0)
	cout<<pow(2,n)<<" ";	
	else 
	for(int i =pow(2,l);i<=pow(2,n)-pow(2,r)+1;i++)
	cout<<i<<" ";
	cout<<endl;
	
	return ;
}


int main()
{
	int t;
	// sc_int(t);
	// while(t--)
	solve();
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值