牛客小白月賽97

薛定谔的AC發表於2024-06-30

比賽連結:牛客小白月賽97


A

思路

程式碼

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;

int num[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    num[a]++;
  }
  for (int i = 1; i <= 100; i++) {
    if (num[i] >= 3) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}

B

思路

程式碼

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;

ll a[N];
int main() {
  int n, flag = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      flag = 1;
    }
  }
  if (flag == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}

C

思路

程式碼

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;

ll qsm(ll x, ll y) {
  ll res = 1;
  while (y) {
    if (y & 1) {
      res *= x;
      res %= mod;
    }
    x *= x;
    x %= mod;
    y /= 2;
  }
  return res;
}

ll c(ll x, ll y) {
  ll res = 1;
  for (ll i = x + 1; i <= y; i++) {
    res *= i;
    res %= mod;
  }
  ll res2 = 1;
  for (ll i = y - x; i >= 1; i--) {
    res2 *= i;
    res2 %= mod;
  }
  res *= qsm(res2, mod - 2);
  res %= mod;
  return res;
}

int main() {
  int n, x;
  cin >> n >> x;
  ll now = pow(sqrt(x), 2), num = sqrt(x);
  if (num < n) {
    cout << 0 << endl;
    return 0;
  }
  ll res = 1;
  for (int i = num; i > n; i--) {
    res += c(n - 1, i - 1);
    res %= mod;
  }
  cout << res ;

  return 0;
}

D

思路

程式碼



E

思路

程式碼



F

思路

程式碼


相關文章