Codeforces Round #739 (Div. 3)
A. Dislike of Threes
简单的水题,预处理即可
AC_CODE
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 1e5 + 10;
int a[N];
void solve() {
int n; read(n);
printf("%d\n", a[n]);
}
signed main()
{
int p = 1;
for(int i = 1; p < 1110; i ++ ) {
if(i % 3 == 0 || i % 10 == 3) continue;
a[p ++ ] = i;
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
B. Who's Opposite?
sb题
找到这个环的中间位置,然后判断三个数字是否在环外即可
AC_CODE
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
void solve() {
int a, b, c;
read(a); read(b); read(c);
if(a > b) swap(a, b);
int res = b - a;
int len = res * 2;
if(b > len || c > len) {
puts("-1");
return;
}
int ans = c + res;
if(ans > 2 * res) ans %= (2 * res);
printf("%d\n",ans);
}
signed main()
{
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
C - Infinity Table
预处理出所有的平方数
- 首先判断这个数字是在哪一行or哪一列 (开方向上取整即可) 假设这个数字是idx
- 其次判断这个数字是在列还是行
- 如果是列 则输出 n - \(idx^2\) 如果是行则输出 \((idx+1)^2\) - n + 1
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 1e5 + 10;
int a[N];
int p = 1;
void solve() {
int n; read(n);
int idx = lower_bound(a + 1, a + 1 + p, n) - a;
int res = n - a[idx - 1];
if(res <= idx) {
printf("%d %d\n", res, idx);
return;
}
res = a[idx] - n;
printf("%d %d\n", idx, res + 1);
}
signed main()
{
for(int i = 1; i <= INF / i; i ++ ) {
a[p ++] = i * i;
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
D - Make a Power of Two
预处理出所有的 \(2^n\)
暴力枚举从原来的数字操作到 \(2^n\) 所需的最小操作次数 取最小值
最小操作次数判断时候,即是判断重复子序列长度
AC_CODE
//#pragma GCC optimize (2)
//#pragma G++ optimize (2)
#include <bits/stdc++.h>
using namespace std;
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
string a[63];
void solve() {
string x; cin >> x;
int ans = INF;
int p = x.size();
for(int i = 0; i < 63; i ++ ) {
int len = a[i].size(), tt = 0;
for(int j = 0; j < p; j ++ ) {
if(tt < len && x[j] == a[i][tt]) tt ++;
}
int r = len - tt + p - tt;
ans = min(ans, r);
if(ans > r) {
cout << i << endl;
ans = r;
}
}
printf("%d\n", ans);
}
signed main()
{
for(int i = 0; i < 63; i ++ ) {
LL p = (1LL << i);
a[i] = to_string(p);
}
int T = 1;cin >> T;
while(T -- ) solve();
return 0;
}
E - Polycarp and String Transformation
题意
对于一个字符串\(a\) 给出\(a\)经过以下操作获得的字符串
- \(ans\) = \(a\)
- 每次删去\(a\)中的每个字符(删除\(a\)中的全部的这个字符)得到新的\(a\) \(ans+=a\)
- 进行上述两个操作直到\(a\)为空字符串
给定 \(ans\) 求是否存在 一个\(a\) 可以经过上述操作的到\(ans\)
-若存在 输出 \(a\) 以及操作顺序
-若不存在 输出 \(-1\)
思路
假设存在\(a\),我们通过\(ans\) 就可以得到操作顺序(倒序寻找即可)
没操作一个字符,这个字符就在后面不会出现, 通过这个我们可以知道,
每个字符出现的总次数一定是这个字符出现的轮次的倍数
因此通过判断上述条件即可得出无解的情况
下面我们讨论一下有解的情况
- 我们已经得到了操作字符的顺序
- 由于每个字符在它可能出现的轮次中出现的个数都是一样的,\(a\)中的字符个数可以通过这个结论求出
即 每个字符出现的总次数除以这个字符出现的轮次 - 通过上述两个操作我们可以得到 \(a\) 字符串,然后模拟题中所给操作即可
最后判断模拟得到的字符串是否和给定字符串相同即可
AC_CODE
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define debug(x) cout<<#x" ----> "<<x<<endl
#define rep(i, b, s) for(int i = (b); i <= (s); ++i)
#define pre(i, b, s) for(int i = (b); i >= (s); --i)
//#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII ;
typedef pair<double, double> PDD ;
typedef long long LL;
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
int lowbit(int x){return x&-x;}
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
LL ksm(LL a, LL b) {if (b == 0) return 1; LL ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
void solve() {
vector<int> vis(26);
string p;
string a; cin >> a;
for(int i = (int)a.size() - 1; ~i; i -- ) {
if(!vis[ a[i] - 'a' ]) p.pb(a[i]);
vis[ a[i] - 'a' ] ++;
}
int len = p.size();
int res = 0;
for(int i = 0; i < len; i ++ ) {
int ans = vis[p[i] - 'a'] % (len - i);
if(ans) {
puts("-1");
return;
}
res += vis[p[i] - 'a'] / (len - i);
}
string curr = a.substr(0, res);
string accept = curr, wa = curr, temp;
reverse(all(p));
for(int i = 0; i < len; i ++ ) {
temp = "";
for(int j = 0; wa[j]; j ++ ) {
if(wa[j] != p[i]) temp.pb(wa[j]);
}
accept += temp;
wa = temp;
}
if(accept == a) {
printf("%s %s\n", curr.c_str(), p.c_str());
}
else puts("-1");
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
Codeforces Round #739 (Div. 3)的更多相关文章
- 刷题记录:Codeforces Round #739 (Div. 3)
Codeforces Round #739 (Div. 3) 20210907.网址:https://codeforces.com/contest/1560. --(叹). A 不希望出现带" ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- HDC2021技术分论坛:“积木拼装”,HarmonyOS弹性部署大揭秘!
作者:peitaiyi,华为终端OS产品交付专家 HarmonyOS是一款面向万物互联时代的.全新的分布式操作系统.在传统的单设备系统能力基础上,HarmonyOS提出了基于同一套系统能力.适配多种终 ...
- 使用AVPlayer自定义支持全屏的播放器(五)—Swift重构版本
前言 很早之前开源了一个简单的视频播放器,由于年久失修,效果惨目忍睹,最近特意花时间对其进行了深度重构.旧版本后期不再维护,新版本使用Swift实现,后续会增加更多功能.不想看文字的请自行下载代码-- ...
- Java Swing设计简单商品信息管理系统(java swing+mysql+eclipse)
一.概述 为了管理好商店库存信息,提升店铺管理工作效率,结合实际工作需要,设计和开发本系统,主要用于商店商品信息维护出入库等.包含商品库存信息查看.商品信息修改,新增商品信息,删除信息等功能. 二.功 ...
- 【ASP.NET Core】Blazor+MiniAPI完成文件下载
今天老周要说的内容比较简单,所以大伙伴们不必紧张,能识字的都能学会. 在开始之前先来一段废话. 许多人都很关心,blazor 用起来如何?其实也没什么,做Web的无非就是后台代码+前台HTML(包含J ...
- python selenium + web自动化,切换到新的窗口,元素定位不到?
问题描述: 自动化由首页切换到分页面,打开了一个新的窗口,不过,定位不到这个窗口的元素,通过开发者工具是可以查到这个元素的 原因是: 因为窗口句柄还停留在上一个页面,所以导致无法定位元素.报错 &qu ...
- Python 利用@property装饰器和property()方法将一个方法变成属性调用
在创建实例属性时,如果直接把实例属性暴露出去,虽然写起来简单,但是存在一些风险,比如实例属性可以在外部被修改. 为了限制外部操作,可以通过一个set_score()方法来设置成绩,再通过一个get_s ...
- Jmeter中用例禁用
1.在线程组下创建2个http请求(blogs和baidu),并且在Thread Group 添加[View Results Tree]和[View Results in Table] 2.选择[ba ...
- mybatis关联查询基础----高级映射
本文链接地址:mybatis关联查询基础----高级映射(一对一,一对多,多对多) 前言: 今日在工作中遇到了一个一对多分页查询的问题,主表一条记录对应关联表四条记录,关联分页查询后每页只显示三条记录 ...
- 《剑指offer》面试题28. 对称的二叉树
问题描述 请实现一个函数,用来判断一棵二叉树是不是对称的.如果一棵二叉树和它的镜像一样,那么它是对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 ...
- GLPK下载安装
GLPK下载安装 下载 wget http://ftp.gnu.org/gnu/glpk/glpk-4.65.tar.gz tar -zxvf glpk-4.65.tar.gz 安装 如果你有管理员权 ...