CodeForces Round #555 Div.3
A. Reachable Numbers
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e9 + ;
int N;
set<int> s; int main() {
scanf("%d", &N);
while(s.find(N) == s.end()) {
s.insert(N);
N += ;
while(N % == ) N /= ;
} printf("%d\n", (int) s.size()); return ;
}
B. Long Number
代码:
#include <bits/stdc++.h>
using namespace std; int N;
string s;
int a[]; int main() {
scanf("%d", &N);
cin >> s;
for(int i = ; i <= ; i ++) {
int x;
scanf("%d", &x);
a[i] = x;
} for(int i = ; i < N; i ++) {
if(a[s[i] - ''] > s[i] - '') {
for(int j = i; j < N; j ++) {
if(a[s[j] - ''] >= s[j] - '')
s[j] = a[s[j] - ''] + '';
else break;
}
break;
}
} cout << s << endl; return ;
}
C1. Increasing Subsequence (easy version)
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + ;
int N;
int a[maxn]; int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d", &a[i]);
string ans = ""; int l = , r = N - , pos = ;
while(l <= r) {
if(a[l] < a[r]) {
if(a[l] > pos) {
pos = a[l];
l ++;
ans += 'L';
} else if(a[r] > pos) {
pos = a[r];
r --;
ans += 'R';
} else break;
} else {
if(a[r] > pos) {
pos = a[r];
r --;
ans += 'R';
} else if(a[l] > pos) {
pos = a[l];
l ++;
ans += 'L';
} else break;
}
} printf("%d\n", ans.length());
cout << ans << endl; return ;
}
C2. Increasing Subsequence (hard version)
代码(在两边一样的情况下只能选左或右跑了):
#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + ;
int N;
int pos = ;
int a[maxn];
string ans1 = "", ans2 = "", ans = ""; string Left(int st, int en, string s) {
string t = s;
int l = st, r = en;
while(l <= r) {
if(a[l] > pos) {
pos = a[l];
l ++;
t += 'L';
} else break;
}
return t;
} string Right(int st, int en, string s) {
string t = s;
int l = st, r = en;
while(l <= r) {
if(a[r] > pos) {
pos = a[r];
r --;
t += 'R';
} else break;
}
return t;
} int main() {
scanf("%d", &N);
for(int i = ; i < N; i ++)
scanf("%d", &a[i]); int l = , r = N - ;
int tp = ;
while(l <= r) {
if(a[l] < a[r]) {
if(a[l] > pos) {
pos = a[l];
l ++;
ans += 'L';
} else if(a[r] > pos) {
pos = a[r];
r --;
ans += 'R';
} else break;
} else if(a[l] > a[r]) {
if(a[r] > pos) {
pos = a[r];
r --;
ans += 'R';
} else if(a[l] > pos) {
pos = a[l];
l ++;
ans += 'L';
} else break;
} else {
int poo = pos;
ans1 = ans, ans2 = ans;
ans1 = Left(l, r, ans);
pos = poo;
ans2 = Right(l, r, ans);
if(ans1.length() > ans2.length())
//cout << ans1 << endl;
ans = ans1;
else //cout << ans2 << endl;
ans = ans2;
break;
}
} printf("%d\n", ans.length());
cout <<ans <<endl; return ;
} /* 15
37504 79054 80071 95721 135743 164345 189260 190810 191657 196168 200000 200000 190810 190018 185437 */
E. Minimum Array
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + ;
int N;
int a[maxn], c[maxn]; int main() {
multiset<int> s;
scanf("%d", &N);
for(int i = ; i <= N; i ++)
scanf("%d", &a[i]);
for(int i = ; i <= N; i ++) {
int x;
scanf("%d", &x);
s.insert(x);
}
for(int i = ; i <= N; i ++) {
int now = N - a[i] % N;
multiset <int>::iterator it = s.lower_bound(now);
if(it == s.end()) it = s.begin();
c[i] = (a[i] + (*it)) % N;
s.erase(it);
} for(int i = ; i <= N; i ++)
printf("%d%s", c[i], i != N ? " " : "\n"); return ;
}
省赛之后脑子一点都不 丝滑? 暴躁 coder 在线可爱
CodeForces Round #555 Div.3的更多相关文章
- 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution
对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...
- Codeforces Round #555 (Div. 3) AB
A: http://codeforces.com/contest/1157/problem/A 题意:每次加到10的整数倍之后,去掉后面的0,问最多有多少种可能. #include <io ...
- Codeforces Round #555 (Div. 3) E. Minimum Array
题意:b数组可以自由排序,c[i]=(a[i]+b[i])%n. 题目中要求c数组的字典序是最小的.那么我们需要尽量满足前面的c[i],才能使字典序最小. 我们知道a[i]和b[i]都是[0,n-1] ...
- Codeforces Round #555 (Div. 3)[1157]题解
不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreago ...
- Codeforces Round #555 (Div. 3) c2 d e f
c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...
- Codeforces Round #555 (Div. 3) D. N Problems During K Days 【数学思维】
一 题面 D. N Problems During K Days 二 分析 对于这题,刚开始我就是陷入了对公式的执着,企图用公式直接确定第一个数,然后试着去找序列.经过思考和手动模拟后发现是很难保证正 ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
- Codeforces Round #555 (Div. 3) E. Minimum Array 【数据结构 + 贪心】
一 题面 E. Minimum Array 二 分析 注意前提条件:$0 \le a_{i} \lt n$ 并且 $0 \le b_{i} \lt n$.那么,我们可以在$a_{i}$中任取一个数 ...
- Codeforces Round #555 (Div. 3) A B C1(很水的题目)
A. Reachable Numbers 题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数. 代码 #include<cstdio& ...
随机推荐
- 特征提取方法: one-hot 和 TF-IDF
one-hot 和 TF-IDF是目前最为常见的用于提取文本特征的方法,本文主要介绍两种方法的思想以及优缺点. 1. one-hot 1.1 one-hot编码 什么是one-hot编码?one-ho ...
- JS中some()和every()和join()和concat()和pop(),push(),shift(),unshfit()和map()和filter()
一.Array 1.some()和every() some()是对数组中每一项运行指定函数,如果该函数对任一项返回true,则返回true. every()是对数组中的每一项运行给定函数,如果该函数对 ...
- The connection to the server localhost:8080 was refused - did you specify the right host or port?
The connection to the server localhost:8080 was refused - did you specify the right host or port? 解决 ...
- Asp.Net Core WebApi中接入Swagger组件(初级)
开发WebApi时通常需要为调用我们Api的客户端提供说明文档.Swagger便是为此而存在的,能够提供在线调用.调试的功能和API文档界面. 环境介绍:Asp.Net Core WebApi + S ...
- SLAM+语音机器人DIY系列:(四)差分底盘设计——6.底盘里程计标
摘要 运动底盘是移动机器人的重要组成部分,不像激光雷达.IMU.麦克风.音响.摄像头这些通用部件可以直接买到,很难买到通用的底盘.一方面是因为底盘的尺寸结构和参数是要与具体机器人匹配的:另一方面是因为 ...
- SpringMVC之Controller和参数绑定
在上一篇Spring+SpringMVC+Mybatis整合中说到了SSM的整合,并且在其中添加了一个简单的查询功能,目的只是将整个整合的流程进行一个梳理,下面在上一篇中工程的基础上再说一些关于Spr ...
- 字符型液晶屏模拟控件(En)
A replica CLCD module control. Initiated on May 5, 2012 Updated on Feb 21, 2017 Copyright 2012-2017 ...
- C# 委托链(多播委托)
委托既可以封装一个方法,又可以对同一类型的方法进行封装,它就是多播委托 using System; using System.Collections.Generic; using System.Lin ...
- 在ASP.NET Core中构建路由的5种方法
原文链接 :https://stormpath.com/blog/routing-in-asp-net-core 在ASP.NET Core中构建路由的5种方法 原文链接 :https://storm ...
- 【设计模式】单例模式 Singleton Pattern
通常我们在写程序的时候会碰到一个类只允许在整个系统中只存在一个实例(Instance) 的情况, 比如说我们想做一计数器,统计某些接口调用的次数,通常我们的数据库连接也是只期望有一个实例.Windo ...