牛客小白赛7 部分题解

A

就是一个简单的递归;

看懂就ok

#include<iostream>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    if(n < 20180001) cout << n + 2017;
    else cout << 20182017 << endl;
    return 0;
}

B

SG函数的运用;

f[i]里面的值可以是1 和 a+1到b+1;

#include <iostream>
 
#include <cstring>
 
#define maxn 100005
 
typedef long long ll;
 
using namespace std;
 
ll SG[maxn],s[12];
ll f[12];
 
void sg(int n,int k)
{
    for(int i = 1; i <= n; i++)
    {
        memset(s,0,sizeof(s));
        for(int j = 0; f[j] <= i && j < k; j ++)
        {
            s[SG[i-f[j]]] = 1;
        }
        for(int j = 0; ; j ++)
        {
            if(!s[j])
            {
                SG[i] = j;
                break;
            }
        }
    }
}
int main()
{
    ll t,a,b;
    cin >> t >> a >> b;
     
    ll w = 0;
    f[w++] = 1;
    for(int j = a + 1; j <= b + 1; j ++)
    {
        f[w++] = j;
    }
    sg(t,w);
    if(SG[t]) cout << "Alice" <<endl;
    else cout << "Bob" <<endl;
     
    return 0;
}

C

第一个人的概率就是自己的概率

第二个人是第一个人赢不了的概率乘第二个人赢得概率

#include <bits/stdc++.h>
 
#define maxn 100005
 
typedef long long ll;
 
using namespace std;
 
int main()
{
    double n,m;
    cin >> n >> m;
    n /= 100.0;
    m /= 100.0;
    if(n > (1 - n) * m)
    {
        cout << "MWH" << endl;
    }
    else if(n == (1 - n) * m)
    {
        cout << "equal" << endl;
    }
    else
    {
        cout << "CSL" << endl;
    }
    return 0;
}

E

模拟就好

#include <bits/stdc++.h>
 
#define maxn 100005
 
typedef long long ll;
 
using namespace std;
 
int main()
{
    ll n,m;
    cin >> n >> m;
    if(m == 1 && n != 1)cout << "No" << endl;
    else
    {
        if(n == 1)cout << "Yes" << endl;
        else
        {
            while(n >= m)
            {
                n -= m;
                n += 1;
            }
            if(n == 1)cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    return 0;
}

F

c++选手stl模板

#include <bits/stdc++.h>

#define maxn 100005

typedef long long ll;

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i <= s.length() ; i ++)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            s[i] += 32;
        }
    }

    ll f = s.find("bob");
    if(f == string::npos)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << f << endl;
    }
    return 0;
}

G

思路:

01背包取一半

#include <bits/stdc++.h>
  
#define maxn 100005
  
typedef long long ll;
  
using namespace std;
  
ll a[maxn];
ll dp[105][maxn];
int main()
{
  
    ios::sync_with_stdio(false);
    ll n,s = 0;
    cin >> n;
    ll m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    m=s/2;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= m; j ++)
        {
            if(j >= a[i])
            {
                dp[i][j] = max(dp[i-1][j-a[i]]+a[i],dp[i-1][j]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    if(s - dp[n][m] > dp[n][m])
    {
        cout << dp[n][m] << ' ' << s - dp[n][m] << endl;
    }
    else
    {
        cout << s - dp[n][m] << ' ' << dp[n][m] << endl;
     }
  
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zzzanj/article/details/82808215