比赛链接:https://codeforces.com/contest/1397

A. Juggling Letters

题意

给出 $n$ 个字符串,可在字符串间任意移动字母,问最终能否使这 $n$ 个字符串相同。

题解

如果可以,因为 $n$ 个字符串相同,所以每个字母的数量一定是 $n$ 的倍数。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n;
cin >> n;
vector<int> cnt(26);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (char c : s) ++cnt[c - 'a'];
}
bool ok = all_of(cnt.begin(), cnt.end(), [&](int x) {
return x % n == 0;
});
cout << (ok ? "YES" : "NO") << "\n";
} int main() {
int t;
cin >> t;
while (t--) solve();
}

B. Power Sequence

题意

给出一个大小为 $n$ 的数组 $a$,允许操作如下:

  • 重排数组,无花费
  • 将一个数 $+1$ 或 $-1$,花费为 $1$

找出使得数组 $a$ 满足 $a_i = c^i$ 的最小花费。

题解

指数增长,枚举 $c$ 即可。

因为 $3 \le n \le 10^5, 1 \le a_i \le 10^9$,所以可以将上限设为 $10^{14}$,一旦有 $c^i$ 大于这个上限就停止枚举。

代码

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
ll ans = LLONG_MAX;
for (int c = 1; true; c++) {
bool too_big = false;
ll change = 0;
ll cur = 1;
for (int i = 0; i < n; i++) {
change += abs(a[i] - cur);
cur *= c;
if (cur > 1e14) {
too_big = true;
break;
}
}
if (too_big) break;
ans = min(ans, change);
}
cout << ans << "\n";
}

C. Multiples of Length

题意

给出一个大小为 $n$ 的数组 $a$,操作如下:

  • 选择一个区间,给其中的每个数加上区间长度的一个倍数

共要进行 $3$ 次操作,找出使得数组 $a$ 满足 $a_i = 0$ 的一种方案。

题解

$gcd(n,n-1)=1$,所以选择一次长为 $n$ 的区间,两次长为 $n - 1$ 的区间。

代码

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
if (n == 1) {
cout << 1 << ' ' << 1 << "\n" << -a[0] << "\n"
<< 1 << ' ' << 1 << "\n" << 0 << "\n"
<< 1 << ' ' << 1 << "\n" << 0 << "\n";
return 0;
}
cout << 1 << ' ' << n << "\n";
for (int i = 0; i < n; i++) {
cout << -a[i] * n << " \n"[i == n - 1];
}
cout << 1 << ' ' << n - 1 << "\n";
for (int i = 0; i < n - 1; i++) {
cout << a[i] * (n - 1) << " \n"[i == n - 2];
}
cout << 2 << ' ' << n << "\n";
for (int i = 1; i < n; i++) {
cout << a[i] * (i == n - 1 ? n - 1 : 0) << " \n"[i == n - 1];
}
}

D. Stoned Game

题意

有 $n$ 堆石子,两个人每次从另一个人没取过的石子堆中拿走一颗石子,无法再取者败,判断最终胜者。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n;
cin >> n;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a.begin(), a.end());
if (a.back() > sum - a.back())
cout << "T" << "\n";
else
cout << (sum & 1 ? "T" : "HL") << "\n";
} int main() {
int t;
cin >> t;
while (t--) solve();
}

Codeforces Round #666 (Div. 2)的更多相关文章

  1. Codeforces Round #666 (Div. 2) Power Sequence、Multiples of Length 思维

    题目链接:Power Sequence 题意: 给你n个数vi,你可以对这个序列进行两种操作 1.可以改变其中任意个vi的位置,无成本 2.可以对vi进行加1或减1,每次操作成本为1 如果操作之后的v ...

  2. Codeforces Round #666 (Div. 2) C. Multiples of Length (构造,贪心)

    题意:有一个长度为\(n\)的序列,可以操作\(3\)次,每次选取一段区间,然后区间的元素加减区间长度的倍数,\(3\)次操作后使得序列所有元素为\(0\),问具体操作情况. 题解:假如我们能选择一整 ...

  3. Codeforces Round #666 (Div. 2) B. Power Sequence (枚举)

    题意:有一个长度为\(n\)的序列,你每次可以对序列重新排序,然后花费\(1\)使某个元素加减\(1\),多次操作后使得新序列满足\(a_{i}=c^i\),\(c\)是某个正整数,求最小花费. 题解 ...

  4. Codeforces Round #666 (Div. 2) C. Multiples of Length (贪心)

    题意:给你一个由\(0,1,?\)组成的字符串,你可以将\(?\)任意改成\(0\)或\(1\),问你操作后能否使得该字符串的任意长度为\(k\)的区间中的\(0\)和$1的个数相等. 题解:我们首先 ...

  5. Codeforces Round #532 (Div. 2) 题解

    Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. NOIP初赛篇——08计算机安全知识

    引言 ​ 计算机安全中最重要的是存储数据的安全,其面临的主要威胁包括:计算机病毒.非法访问.计算机电磁辐射.硬件损坏等. ​ 计算机病毒是附在计算机软件中的隐蔽小程序,它和计算机其他工作程序一样,但会 ...

  2. Angular入门到精通系列教程(7)- 组件(@Component)基本知识

    1. 概述 2. 创建Component 组件模板 视图封装模式 特殊的选择器 :host inline-styles 3. 总结 环境: Angular CLI: 11.0.6 Angular: 1 ...

  3. mmall商城分类模块总结

    后台分类model的开发具体功能有:添加分类名称,修改分类名称,查询所有子分类,查询父分类以及它下面的子分类(递归) 需要注意的是,在后台管理进行操作的时候,都需要验证当前用户是否是管理员的角色,不管 ...

  4. Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT 故障排除

    系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...

  5. python函数1-函数基础

  6. 【Docker】Docker概述、理解docker的集装箱、标准化、隔离的思想、 docker出现解决了什么问题

    整理一下 慕课网 第一个docker化的java应用 Docker环境下的前后端分离项目部署与运维 课程时所做的笔记 Docker概述 docker - https://www.docker.com/ ...

  7. 通过show profile分析sql语句

    set profling=1; select count(*) from xuehao; show profiles; show profile for query 1; mysql> set ...

  8. 技术实践丨React Native 项目 Web 端同构

    摘要:尽管 React Native 已经进入开源的第 6 个年头,距离发布 1.0 版本依旧是遥遥无期."Learn once, write anywhere",完全不影响 Re ...

  9. LeetCode653. 两数之和 IV - 输入 BST

    题目 直接暴力 1 class Solution { 2 public: 3 vector<int>ans; 4 bool findTarget(TreeNode* root, int k ...

  10. ctfhub技能树—web前置技能—http协议—Cookie

    打开靶机环境 查看显示内容 根据提示,需要admin登录才能得到flag 题目介绍为Cookie欺骗.认证.伪造 介绍一下cookie和session 一.cookie: 在网站中,http请求是无状 ...