Educational Codeforces Round 181 (Rated for Div. 2) A-C

A. Difficult Contest

题目大意

给你一个串,要求串内不能出现FFT或者NTT

思路

提取出串内所有的T,放在最前面

cpp 复制代码
// Author: zengyz
// 2025-08-02 14:43

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve()
{
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'T')
      count++;
  while (count--)
    cout << "T";
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == 'T')
      continue;
    cout << s[i];
  }
  cout << endl;
  return;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int _T = 1;
  cin >> _T;
  while (_T--)
  {
    solve();
  }
  return 0;
}

B. Left and Down

题目大意

给你a,b,期望从点(a,b) 移动到终点(0,0)

每次可以选择一个不超过k大小的dx和Dy

并移动到(a-dx,b-dy)处

可以进行如下两个操作:

如果(dx,dy)第一次出现,花费为1

如果(dx,dy)重复出现,则不花费

问最少花费为多少

思路

先对其求gcd,设其gcd为tmp,且(a,b)可以由(a/tmp和b/tmp)重复tmp次获得

如果(a/tmp和b/tmp)均小于等于k,那么可以由tmp次(a/tmp和b/tmp)

花费为1

否则花费为2

cpp 复制代码
// Author: zengyz
// 2025-08-02 14:56

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
void solve()
{
  ll a, b, k;
  cin >> a >> b >> k;
  ll tmp = gcd(a, b);
  a /= tmp, b /= tmp;

  ll maxx = max(a, b);
  if (maxx <= k)

    cout << 1 << endl;
  else
    cout << 2 << endl;
  return;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int _T = 1;
  cin >> _T;
  while (_T--)
  {
    solve();
  }
  return 0;
}

C. Count Good Numbers


题目大意

我们称一个数为好的如果他的因式分解中所有的素数都至少有两位(大于等于10)

问在l到r之间有多少个这样的数

思路

10以下的素数只有2、3、5、7,考虑容斥原理去除所有包含2,3,5,7的数即可

cpp 复制代码
// Author: zengyz
// 2025-08-02 15:26

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve()
{
  ll l, r;
  cin >> l >> r;
  auto calc = [&](ll x) -> ll
  {
    ll tmp = 0;
    tmp -= x / 2;
    tmp -= x / 3;
    tmp -= x / 5;
    tmp -= x / 7;
    tmp += x / 6;
    tmp += x / 10;
    tmp += x / 14;
    tmp += x / 15;
    tmp += x / 21;
    tmp += x / 35;
    tmp -= x / 30;
    tmp -= x / 42;
    tmp -= x / 70;
    tmp -= x / 105;
    tmp += x / 210;
    return tmp;
  };
  cout << r - l + 1 + calc(r) - calc(l - 1) << endl;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int _T = 1;
  cin >> _T;
  while (_T--)
  {
    solve();
  }
  return 0;
}
相关推荐
_bong1 分钟前
python语言中的常用容器(集合)
开发语言·python
沪漂的码农16 分钟前
MCU时钟源深度解析:内部晶振与外部晶振的技术博弈
c语言·单片机·嵌入式硬件
布伦鸽17 分钟前
C# WPF DataGrid 数据绑定时的单元格编辑类型模板
开发语言·c#·wpf
tqs_1234524 分钟前
分sheet写入excel
开发语言·python·算法
Roc-xb25 分钟前
解决Compile Run插件运行c/c++中文乱码问题
c语言·开发语言·c++
0wioiw025 分钟前
Esp32基础(①②大模型控制)
开发语言·python
eqwaak032 分钟前
Pillow高级实战案例:图像处理的进阶应用
开发语言·python·科技·语言模型·pillow
dengzhenyue35 分钟前
矩形碰撞检测
开发语言·前端·javascript
凤年徐40 分钟前
【C++模板编程】从泛型思想到实战应用
java·c语言·开发语言·c++
饿了我会自己捡代码吃1 小时前
【MySQL】使用C/C++链接mysql数据库
c语言·数据库·mysql