首页 > 其他分享 >20240813

20240813

时间:2024-09-23 11:46:22浏览次数:1  
标签:cnt int ++ -- while Solve 20240813

Goals, Goals! Everywhere

先考虑最大的情况,那就是没有助攻,全是进球,观察样例,发现好像最小进球数好像就是最大数除以 \(2\),但是有一种特殊情况,就是最大的那个球员比剩下的球员加起来还多(C罗和国足)

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3e5 + 5;

int t, n, a[N], sum;

void Solve() {
  cin >> n;
  sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a + 1, a + n + 1);
  if (n == 1) {
    cout << sum << " " << sum << "\n";
  }
  else {
    if (sum - a[n] >= a[n]) {
      cout << (sum + 1) / 2 << " " << sum << "\n";
    }
    else cout << a[n] << " " << sum << "\n";
  }
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}

Game of Primes

如果 \(F(x) 与 \frac{x}{F(x)}\) 都是质数,那么 \(Antwan\) 对它毫无办法,如果都不是那么也不用管,所以 \(Ammar\) 和 \(Antwan\) 抢夺的是其中又一个是质数的,所以答案就是两个都是的加上只有一个是的除以\(2\)

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 3e5 + 5;

int t, n, a[N], cnt[3], p[1000005];

bool vis[1000005];

void Solve() {
  cin >> n;
  cnt[1] = cnt[2] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int x = p[a[i]];
    cnt[2 - (vis[x] + vis[a[i] / x])]++;
  }
  cout << cnt[2] + (cnt[1] + 1) / 2 << "\n";
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 2; i <= 1000000; i++) {
    if (vis[i]) {
      continue;
    }
    p[i] = 1;
    for (int j = i * 2; j <= 1000000; j += i) {
      vis[j] = true;
      if (!p[j]) {
        p[j] = i;
      }
    }
  }
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}

Good Array

我们可以将 \(2\) 全部取出,然后二分答案即可

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int t, n, a[N], cnt[N], cur;

bool check(int x) {
  int cnt = cur, ret = 0;
  for (int i = n; i >= 1; i--) {
    if (a[i] >= x) ret++;
    else {
      int y = a[i];
      while (cnt && y < x) {
        y *= 2;
        cnt--;
      }
      if (y >= x) {
        ret++;
      }
    }
  }
  return ret >= x;
}

void Solve() {
  cin >> n;
  cur = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cur++;
    }
  }
  sort(a + 1, a + n + 1);
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (check(mid)) {
      l = mid;
    }
    else r = mid - 1;
  }
  cout << l << "\n";
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}

标签:cnt,int,++,--,while,Solve,20240813
From: https://www.cnblogs.com/libohan/p/18426800

相关文章

  • [20240813]跟踪sqlplus登录执行了什么5(21c).txt
    [20240813]跟踪sqlplus登录执行了什么5(21c).txt--//跟踪看看sqlplus21c版本访问数据库21c时,在执行用户调用命令前执行一些什么sql语句。1.环境:[email protected]:1521/book>@prxx==============================PORT_STRING                  :x86_64/L......
  • 20240813:组合计数选做
    P3214[HNOI2011]卡农题意:\(m\)个集合,\(n\)种元素,求集合间互不相同且每种元素出现偶数次的方案数。题目等价于从\(1\sim2^n-1\)里选出\(m\)个不同的数,使他们异或和为\(0\)。不妨对每个数标号,由于互不相同,最后除以\(m!\)即可。设\(f_i\)表示前\(i\)个数异或......