牛客小白月赛63 A~E题题解

文章目录

A

思路:根据&运算的性质,直接循环一遍即可。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;
int a[N];

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int n;
     cin >> n;
     cin >> a[1];
     int k = a[1];
     for (int i = 2; i <= n; i++)
     {
          cin >> a[i];
          k &= a[i];
     }
     cout << k << endl;
     return 0;
}

B

思路:读清题意模拟即可。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;
int a[N];

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int n, m;
     cin >> n >> m;
     int M = m;
     for (int i = 1; i <= n; i++)
          cin >> a[i];
     int k = 2;
     int ans = 0;
     int cnt = 0;
     while (m--)
     {
          cnt++;
          int sum = 0;
          for (int i = 1; i <= n; i++)
          {
               if (a[i] > k)
                    a[i] -= k;
               else if (a[i] < k)
                    a[i] = 0;
               else if (a[i] == k)
               {
                    k++;
                    a[i] = 0;
               }
               if (a[i] == 0)
                    sum++;
          }
          ans += k;
          if (sum == n)
               break;
     }
     if (!m)
          cout << ans << endl;
     else
          cout << ans + k * (M - cnt) << endl;
     return 0;
}

C

思路:dfs搜索全排列,并处理胜负情况即可。
注意输出循序:本人nt

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 15;
int a[N], b[N];
int ans[N];
bool st[N];
int n;
int Ping, Lose, Win;

void dfs1(int u)
{
     if (u == n)
     {
          int sum = 0;
          for (int i = 0; i < n; i++)
          {
               if (ans[i] > b[i + 1])
                    sum++;
               else if (ans[i] < b[i + 1])
                    sum--;
          }
          if (sum > 0)
               Win++;
          else if (sum == 0)
               Ping++;
          else if (sum < 0)
               Lose++;
          return;
     }
     for (int i = 1; i <= n; i++)
     {
          if (st[i] == false)
          {
               ans[u] = a[i];
               st[i] = true;
               dfs1(u + 1);
               st[i] = false;
          }
     }
}

int main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     cin >> n;
     int sum = 0;
     for (int i = 1; i <= n; i++)
          cin >> a[i];
     for (int i = 1; i <= n; i++)
          cin >> b[i];
     dfs1(0);
     cout << Win << ' ' << Lose << ' ' << Ping << endl;
     return 0;
}

D

思路:贪心三个为一组,前两个是最小的,第三个是第二小的,判一下最后一个是否个第一个相等相等的话,改成第二小的。

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define int long long
const int N = 1e6 + 10;
int a[N];

signed main()
{
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int n, m;
     cin >> n >> m;
     for (int i = 1; i <= m; i++)
          cin >> a[i];
     sort(a + 1, a + m + 1);
    if(m==1)
    {
        cout<<"Ginger666"<<endl;
        return 0;
    }
     int ans = 0;
     for (int i = 1; i <= n; i++)
     {
          if (i % 3 == 1 || i % 3 == 2)
               ans += a[1];
          else if (i % 3 == 0)
               ans += a[2];
     }
     if (n % 3)
     {
          ans -= a[1];
          ans += a[2];
     }
     cout << ans << endl;
     return 0;
}

E

思路:
在这里插入图片描述

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define int long long
const int mod = 998244353;

signed main()
{
     ios::sync_with_stdio(false);
     int n;
     cin >> n;
     if (n == 1)
     {
          puts("1");
          return 0;
     }
     int ans = 0;
     for (int i = 1; i <= n; i++)
     {
          ans = (ans + (n - i) * (i * n + i) - i * (i + 1 + n) * (n - i) / 2) % mod;
     }
     for (int i = 1; i <= n - 2; i++)
     {
          ans = ans * i % mod;
     }
     cout << ans * 2 % mod << endl;
     return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值