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;
}
相关推荐
LDR0064 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术4 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园4 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob4 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享4 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.4 天前
C语言--day30
c语言·开发语言
玖玥拾4 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
何以解忧,唯有..4 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽4 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
云水一下4 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php