牛客练习赛89

比赛地址 https://ac.nowcoder.com/acm/contest/11179#question

牛客练习赛89

A

   由题可知先输入n,k,s,最后需要求出s米粒的方法,而题目中丢失或者是拿走米粒均是 2 w 2^{w} 2w(w为任意数字),所以可以将s转化为2进制表示,只要在k个格子里,去掉了2进制表示情况下的s里的“1”,就肯定无法选出来方案了。

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

#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define ref(i, x, y) for (int i = (x); i < (y); i++)
typedef long long ll;

int main()
{
    IOS;
    int num = 0, flag = 1;
    ll n, k, s;
    cin >> n >> k >> s;
    bitset<70> a(s);

    ref(i, 0, k)
    {
        cin >> num;
        if (a[--num] == 1)
            flag = 0;
    }
    //注意这个数组和直接cout是反着来的

    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    system("pause");
    return 0;
}

B

   数据规模较小,dfs

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);

string a = "cocacola";
string b;
int ans = 100000;

void dfs(int p, int cnt)
{
    if (p == 8)
    {
        ans = min(ans, cnt);
        return;
    }
    if (b[p] == a[p])
        dfs(p + 1, cnt);
    else
    {
        for (int i = p + 1; i < 8; i++)
            if (b[i] == a[p])
            {
                swap(b[p], b[i]);
                dfs(p + 1, cnt + 1);
                swap(b[p], b[i]);
            }
    }
}

int main()
{
    IOS;
    cin >> b;
    dfs(0, 0);
    cout << ans << endl;
    
    system("pause");
    return 0;
}

C

   因为只能向下或者向右走,而且有两个人,两人各走过n+2个格子,但由于起点和终点没有豆子,所以每个人只有n个,由题得知两人的路线必定不重叠,而且起始位置,只能一个人往下,一个人向右。

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

#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define ref(i, x, y) for (int i = (x); i < (y); i++)
typedef long long ll;
static const ll MAXN = 2e6 + 10;

bool a[5][MAXN];

int main()
{
    IOS;
    int n = 0, m = 0, x = 0, y = 0;
    cin >> n >> m;
    ref(i, 0, m)
    {
        cin >> x >> y;
        x--;
        y--;
        a[x][y] = 1;
    }

    int f0min, f0max, f1min, f1max, f2min, f2max;
    ref(i, 0, n)
    {
        if (a[0][i] == 1)
        {
            f0min = i;
            break;
        }
    }
    ref(i, 0, n)
    {
        if (a[0][i] == 1)
            f0max = i;
    }

    ref(i, 0, n)
    {
        if (a[1][i] == 1)
        {
            f1min = i;
            break;
        }
    }
    ref(i, 0, n)
    {
        if (a[1][i] == 1)
            f1max = i;
    }

    ref(i, 0, n)
    {
        if (a[2][i] == 1)
        {
            f2min = i;
            break;
        }
    }
    ref(i, 0, n)
    {
        if (a[2][i] == 1)
            f2max = i;
    }
    
	//满足这个条件才能恰好得出答案
    if ((f0min > f1max + 1 && f1max < n - 2) && (f1min > 1 && f2max < f1min - 1))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    system("pause");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值