首页 > 其他分享 >2022CCPC威海站 铜牌题解 A C D E G I J 补题

2022CCPC威海站 铜牌题解 A C D E G I J 补题

时间:2023-04-26 21:36:37浏览次数:33  
标签:2022CCPC int 题解 long player 补题 using include define

A

//木桶效应
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
map<string, int> cham;
pair<string, int> player[N];
int cnt1[6];
int cnt2[6];
int n, m;
int sum;
signed main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      string s;
      cin >> s;
      cham[s] = 1;
    }
  }

  cin >> m;
  for (int i = 1; i <= m; i++)
  {
    cin >> player[i].first >> player[i].second;
    if (cham[player[i].first] == 1)
    {
      cnt1[player[i].second]++;
    }
    else
    {
      cnt2[player[i].second]++;
    }
  }
  int res = 0x3f3f3f;
  for (int i = 1; i <= 5; i++)
  {
    res = min(res, cnt1[i] + cnt2[i]);
  }
  for (int i = 1; i <= 5; i++)
  {
    sum += cnt1[i];
  }
  res = min(sum, res);
  cout << res;
  return 0;
}

C

由于只需要输出一组可行解我们只要找到一组即可 

结论:5点不共线一定能找到可行解,先固定4个点找到不共线的第五个点让后再枚举5个点之间线段的情况如果点到另外四个点斜率均不同,该点是中心点输出这组可行解

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

#define endl '\n'
#define LL long long
#define ph push_back
#define INF 0x3f3f3f3f
#define PII pair<int, int>
#define y second
#define x first
const int N = 3e5 + 10;
int t;
int n;
PII a[N];
bool flag;
void check()
{
  for (int i = 1; i <= 5; ++i)
  {
    set<PII> sa;
    for (int j = 1; j <= 5; ++j)
    {
      if (i == j)
        continue;
      int x1 = a[i].x;
      int y1 = a[i].y;
      int x2 = a[j].x;
      int y2 = a[j].y;
      int x = x2 - x1;
      int y = y2 - y1;
      int tmp = __gcd(x, y);
      tmp = abs(tmp);
      sa.insert({x / tmp, y / tmp});
    }
    if (sa.size() == 4)
    {
      cout << "YES\n";
      cout << a[i].x << " " << a[i].y << "\n";
      for (int j = 1; j <= 5; ++j)
      {
        if (j != i)
          cout << a[j].x << ' ' << a[j].y << "\n";
      }
      flag = 1;
      return;
    }
  }
}

bool invalid(int k)
{
  set<PII> s;
  int temp;
  int x1;
  int y1;
  for (int i = 1; i <= 4; i++)
  {
    x1 = a[i].x - a[k].x;
    y1 = a[i].y - a[k].y;
    temp = __gcd(x1, y1);
    s.insert({x1 / temp, y1 / temp});
  }
  return s.size() != 1;
}
void solve()
{
  flag = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i].x >> a[i].y;
  for (int i = 5; i <= n; ++i)
  {
    if (invalid(i))
    {
      flag = 1;
      swap(a[i], a[5]);
      break;
    }
  }
  if (flag)
    check();
  else
    cout << "NO\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> t;
  // t = 1;
  while (t--)
  {
    solve();
  }
  return 0;
}

 

 

E

//模拟
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, k; int a[N]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < k) { printf("Python 3.%d will be faster than C++", i); return 0; } } for (int i = n + 1;; i++) { if (a[i - 1] >= a[i - 2]) { cout << " Python will never be faster than C++"; return 0; } else { a[i] = 2 * a[i - 1] - a[i - 2]; if (a[i] < k) { printf("Python 3.%d will be faster than C++", i); return 0; } } } }

 G

打表,用哈希(各种限制条件)暴力算出循环节长度(有点赌),计算结果

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
const int N = 5000010;
int x, n;
i64 l, r;
int ans[N];
int t[N];
u64 ts[N];
u64 tm[N];
u64 xo[N];
int pos;
bool check(int l, int r)
{
  for (int a = 1, b = l + 1; b <= r; a++, b++)
  {
    if (t[a] != t[b])
      return false;
  }
  return true;
}
i64 cal(int x)
{
  int T = x / pos;
  int Z = x % pos;
  return T * ans[pos] + ans[Z];
}
signed main()
{
  cin >> x;
  for (i64 i = 1; i <= 5000000; i++)
  {
    i64 tep = __gcd((i * x) ^ x, x);
    t[i] = tep;
    ts[i] = ts[i - 1] + tep;
    tm[i] = tm[i - 1] + tep * tep;
    xo[i] = xo[i - 1] ^ tep;
    if (tep == 1)
      ans[i] = ans[i - 1] + 1;
    else
      ans[i] = ans[i - 1];
    if (i % 2 == 0)
    {
      int j = i / 2;
      if (ts[j] + ts[j] != ts[i])
        continue;
      if (tm[j] + tm[j] != tm[i])
        continue;
      if (xo[i])
        continue;
      if (__builtin_popcount(i) != 1)
        continue;
      if (!check(j, i))
        continue;
      pos = i;
    } //得到循环节结束的位置,即长度
  }
  cin >> n;
  while (n--)
  {
    cin >> l >> r;
    cout << cal(r) - cal(l - 1) << endl;
  }
}

 

标签:2022CCPC,int,题解,long,player,补题,using,include,define
From: https://www.cnblogs.com/xumaolin/p/17354457.html

相关文章

  • JOISC2016 题解
    仍然是没有做通信题。JOISC2016Day1Matryoshka俄罗斯套娃转化错了,转化成上升子序列了,然后就变成了区间LIS。实际上是LDS,那么就可以直接做了。https://qoj.ac/submission/99648JOISC2016Day1Memory2神经衰弱我们对数进行两两配对,然后把每一对都问出来。如果不存在相......
  • GLIBCXX_3.4.20 not found 问题解决【Unable to load shared library 'lib**.so'】
    前因:问题:在调用别人的so时,出现了如下问题【GLIBCXX_3.4.20notfound】Unabletoloadsharedlibrary'libdbc.so'oroneofitsdependencies.Inordertohelpdiagnoseloadingproblems,considersettingtheLD_DEBUGenvironmentvariable:/lib64/libstdc++.so.6:v......
  • ABC267G Increasing K Times 题解
    做这道题,很有感悟,发篇文。先给数列从小到大排个序。接下来设\(f_{i,j}\)表示前\(i\)个数的排列形成\(j\)个上坡的方案数。接下来考虑转移,分为插入第\(i\)个数后增加上坡和不增加上坡两种情况。对于不增加的情况,有三种可能:第\(i\)个数插入在了数列的最前端,有\(1\)......
  • 2021牛客OI赛前集训营-提高组(第二场)第三题 树数树题解
    题目描述牛牛有一棵\(n\)个点的有根树,根为\(1\)。我们称一个长度为\(m\)的序列\(a\)是好的,当且仅当:\(\foralli\in(1,m]\),\(a_i\)为\(a_{i−1}\)的祖先或\(a_{i−1}\)是\(ai\)的祖先\(\forall1\leqi\ltj\leqm,a_i\neqa_j\)你需要帮助牛牛求出最长的......
  • 2021牛客OI赛前集训营-提高组(第三场) 第二题 交替 题解与结论证明
    题目描述一个长度为\(n\)的数组\(A\),每秒都会变成一个长度为\(n−1\)新数组\(A'\),其变化规则如下:若当前数组\(A\)的长度\(n\)为偶数,则对于新数组\(A'\)的每一个位置\(i(1≤i<n)\)来说,\(A'[i]=A[i]+A[i+1]\)若当前数组\(A\)的长度\(n\)为奇数,则对于......
  • 【SD集训】20230425 T2 差(difference) 题解 CF1500F 【Cupboards Jumps】
    大家可以猜猜看为什么有两个标题,因为这个原因本文就不设密码了,被He_ren的原题创到了。吐槽一下,He_ren甚至出原题还用脚造数据,虽然数据确实比较难造。不过那两个\(O(n^2)\)老哥好像都没最后将所有数调整成非负,遗憾20。有人场切*3500却没过签到题,我不说是谁。题目描述......
  • Net6+axios 返回401 axios不能获取 状态码问题解决
    错误使用app.UseAuthentication();//认证 这里要加,位置不能反app.UseAuthorization();//授权 app.UseCors();//启用Cors解决方法app.UseCors();//启用Corsapp.UseAuthentication();//认证 这里要加,位置不能反app.UseAuthorization();//授权  更换前更换后  ......
  • 题解:【CTS2022】 独立集问题
    题目链接来自2023SDPT-Round1-Day4课上Qingyu的讲解。考虑对于一个点多次操作会发生什么?第一次操作会将周围的点的权值吸过来,自己对答案的贡献乘\(-1\),周围的点的贡献乘\(+1\),得到新的权值\(a_x'=\pma_x\mp\sum_{y\inson_x}a_y\);再一次操作,我们可以将这个新的贡......
  • Mount cifs存储时提示not supported问题解决
    Mountcifs存储时提示notsupported问题解决:报错: mounterror(95):Operationnotsupported排查:1、当时刚好是mount2个存储,结果1个可以1个不行,就反馈给负责存储同事查看2个存储的区别2、存储同事查看后得出不行的是比较老的Netapp存储,mounterror(95)错误应该是不支持的smb协议......
  • leetcode-217-存在重复元素 题解
    题目描述给你一个整数数组nums。如果任一值在数组中出现至少两次,返回true;如果数组中每个元素互不相同,返回false。示例1:输入:nums=[1,2,3,1]输出:true示例2:输入:nums=[1,2,3,4]输出:false示例3:输入:nums=[1,1,1,3,3,4,3,2,4,2]输出:true提......