首页 > 其他分享 >2022四川省赛

2022四川省赛

时间:2022-10-07 22:23:03浏览次数:76  
标签:std 四川省 int pos long constexpr 2022 using

链接:
https://ac.nowcoder.com/acm/contest/42105

A

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

template <typename T>
class Fenwick {
 public:
  int n;
  vector<T> tree;
  Fenwick(const int &n) : n(n), tree(n) {}
  inline void modify(int pos, T x) {
    for ( ; pos <= n; pos += pos & -pos) {
      tree[pos - 1] += x;
    }
  }
  inline T get(int pos) {
    T res = 0;
    for ( ; pos > 0; pos -= pos & -pos) {
      res += tree[pos - 1];
    }
    return res;
  }
  inline T sum(int l, int r) { // (l, r]
    return get(r) - get(l);
  }
};

constexpr int N = 26;

int cnt[N];
int half[N];

void solve() {
  int n;
  string s;
  cin >> n >> s;
  s = " " + s;
  Fenwick<int> f(n);
  vector<vector<int>> pos(26);
  for (int i = 1; i <= n; i++) {
    int num = s[i] - 'a';
    half[num]++;
  }
  for (int i = 0; i < 26; i++) {
    half[i] /= 2;
  }
  vector<int> p(n + 1);
  int tot = 0;
  for (int i = 1; i <= n; i++) {
    int num = s[i] - 'a';
    if (cnt[num] < half[num]) {
      p[i] = ++tot;
      pos[num].push_back(tot);
    } else {
      p[i] = pos[num][cnt[num] - half[num]] + n / 2;
    }
    cnt[num]++;
  }
  i64 ans = 0;
  for (int i = n; i >= 1; i--) {
    ans += f.get(p[i]);
    f.modify(p[i], 1);
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

A和cf一个题差不多

链接:
https://codeforces.com/contest/1430/problem/E

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

template <typename T>
class Fenwick {
 public:
  int n;
  vector<T> tree;
  Fenwick(const int &n) : n(n), tree(n) {}
  inline void modify(int pos, T x) {
    for ( ; pos <= n; pos += pos & -pos) {
      tree[pos - 1] += x;
    }
  }
  inline T get(int pos) {
    T res = 0;
    for ( ; pos > 0; pos -= pos & -pos) {
      res += tree[pos - 1];
    }
    return res;
  }
  inline T sum(int l, int r) { // (l, r]
    return get(r) - get(l);
  }
};

constexpr int N = 26;

int cnt[N];
int half[N];

void solve() {
  int n;
  string s;
  cin >> n >> s;
  s = " " + s;
  Fenwick<int> f(n);
  vector<vector<int>> pos(26);
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    int num = s[i] - 'a';
    pos[num].push_back(i);
  }
  i64 ans = 0;
  for (int i = 1; i <= n; i++) {
    int num = s[i] - 'a';
    p[n - i + 1] = pos[num].back();
    pos[num].pop_back();
  }
  for (int i = n; i >= 1; i--) {
    ans += f.get(p[i]);
    f.modify(p[i], 1);
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

F

找三个素数乘起来就行

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

constexpr int N = 2E6;

vector<int> a;
bool st[N + 1];

void get() {
  for (int i = 2; i <= N; i++) {
    if (!st[i])
      a.push_back(i);
    for (int j = 0; 1LL * a[j] * i <= N; j++) {
      st[i * a[j]] = 1;
      if (i % a[j] == 0)
        break;
    }
  }
}

void solve() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 24 << '\n';
    return;
  }
  int A = *lower_bound(a.begin(), a.end(), 1 + n);
  int B = *lower_bound(a.begin(), a.end(), A + n);
  int C = *lower_bound(a.begin(), a.end(), B + n);
  i64 ans = 1;
  ans *= A;
  ans *= B;
  ans *= C;
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  cin >> tt;
  get();
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

H

map套vector

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<vector<int>, int> mp;
  i64 ans = 0;
  for (int i = 0; i < m; i++) {
    vector<int> b(n);
    for (int j = 0; j < n; j++) {
      cin >> b[j];
    }
    mp[b]++;
  }
  for (auto [u, v] : mp) {
     ans += 1LL * v * (v - 1) / 2;
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

K

套个计算几何旋转向量公式

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

//constexpr int M = 998244353;
//constexpr int M = 1000000007;

const double Pi = acos(-1);

void solve() {
  int t;
  cin >> t;
  double l1, l2, l3;
  cin >> l1 >> l2 >> l3;
  double t1, t2, t3;
  cin >> t1 >> t2 >> t3;
  cout << (-l1 * sin(-360.0 / t1 * t * Pi / 180.0)) + 
  (-l2 * sin(-360.0 / t2 * t * Pi / 180.0)) + 
  (-l3 * sin(-360.0 / t3 * t * Pi / 180.0)) << ' ' <<
  (l1 * cos(-360.0 / t1 * t * Pi / 180.0)) +
  (l2 * cos(-360.0 / t2 * t * Pi / 180.0)) + 
  (l3 * cos(-360.0 / t3 * t * Pi / 180.0));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(10);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

标签:std,四川省,int,pos,long,constexpr,2022,using
From: https://www.cnblogs.com/kiddingma/p/16767342.html

相关文章

  • 2022河南省赛
    链接:https://codeforces.com/gym/103941A#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;//constexprintM=998244353;//constexprint......
  • 2022.10.7第三次组会记录
    团队:集农广益小组地点:桃园食堂时间:晚上九点参与人:全体人员组会内容摘要:分析项目具体架构和功能,讨论数据流图的设计要求组会主要内容:1.分析讨论用户的具体功能:发帖、......
  • 2022上海省赛
    A#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;//constexprintM=998244353;//constexprintM=1000000007;boolno[10];intcnt[1......
  • 2022-2023-1学期 20221417魏正一 《计算机基础与程序设计》第6周学习总结
    第六周学习目标·Polya如何解决问题·简单类型与组合类型·复合数据结构·查找与排序算法·算法复杂度·递归·代码安全学习资源·教材·阅读「反作弊」:任何时......
  • 2022/10/7 T3 boss挑战
    题目地址题目大意:给你敌人的生命值,你的生命值、愤怒值、蓝值,愤怒值可以在普攻造成伤害的同时回复,生命和蓝值可以喝药回,愤怒值和蓝值可以放大招造成伤害,每回合你先选一种行......
  • 逆向工程核心原理——DLL注入 虽然原版是针对win7 32位的 我自己使用vs2022 在win11 6
    逆向工程核心原理——第二十三章 先说我自己本机win1164位上注入记事本的效果:  虽然弹出一个窗口。但是还是成功了:   生成了index.html文件  ......
  • 2022-2023-1 20221407
    进制转换班级......
  • 2022.10.7
    ACM。结果不是很好。一开始的节奏是很好的,但从A题调不出来开始就乱了。每个人再自己的题上都有深入思考,但对别人的情况不了解,所以讨论的效率实际不高,而且很容易被套进死胡......
  • 2022牛客国庆集训派对day6 A(极大矩阵计数)
    2022牛客国庆集训派对day6A(极大矩阵计数)A-All-oneMatrices_2022牛客国庆集训派对day6(nowcoder.com)题目求可以构成给出的01矩阵的全1极大矩阵数目思路悬线法可......
  • 【闲话】2022.10.07
    发现似乎我妈登上博客园了那我是不是该收敛点啊总之今天考了场试啊密码还是我的某中文网名全拼。还是相对论:只要大家都挂了那我就没有挂————bikuhiku看......