当前位置:网站首页>【Codeforces Round #805 (Div. 3)(A~C)】
【Codeforces Round #805 (Div. 3)(A~C)】
2022-07-30 06:04:00 【浪漫主义狗】
更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验
文章目录
A. Round Down the Price
题目大意
- 对于一个数 N N N,求其最接近且不大于该数的 1 0 m 10^m 10m
- 输出 N − 1 0 m N-10^m N−10m
思想
- 初始化
p = 1e10
,循环枚举p = p / 10
直到p < n
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void solve(){
LL n;
cin >> n;
LL p = 1e11;
while(p > n){
p /= 10;
}
cout << n - p <<endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
B. Polycarp Writes a String from Memory
题目大意
- 对于字符串 S S S,每天只能遍历三个不同字母
- 几天可以遍历完 S S S
思想
- 模拟
vis[s[i]]
记录s[i]
是否为新字母,cnt
记录当天的新字母的个数- 当
cnt == 4
说明要开始新的一天,并清空记忆
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
string s;
cin >> s;
int flag = 0;
bool vis[300];
memset(vis,0,sizeof vis);
int cnt = 0;
for(int i = 0; i < s.size(); i ++){
if(!vis[s[i]]){
cnt ++;
if(cnt == 4){
cnt = 1;
flag ++;
memset(vis,0,sizeof vis);
}
vis[s[i]] = 1;
}
}
if(cnt) flag ++;
cout << flag << endl;
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
C. Train and Queries
题目大意
- 顺次给定 n n n个车站,先经过的车站可以走到后面的车站
- 编号可能重复出现,即可能重复经过一个车站
- 对于 k k k次询问,给出起点和终点车站编号,求是否可以从起始站到终点站
思路
map<int,int> l, r
分别存储某一编号的站点最左边的下标和最右边的下标- 对于每次询问,若起始站的最左边的下标小于终点站的最右边的下标,则可行
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, m;
cin >> n >> m;
map<int,int> l, r;
for(int i = 1; i <= n; i ++){
int x;
cin >> x;
if(l[x] == 0){
l[x] = r[x] = i;
}
else{
l[x] = min(l[x],i);
r[x] = max(r[x],i);
}
}
while(m --){
int x, y;
cin >> x >> y;
if(l[x] != 0 && l[y] != 0){
if(l[x] < r[y]) cout << "YES" << endl;
else cout << "NO" << endl;
}
else cout << "NO" << endl;
}
}
int main(){
int _;
cin >> _;
while(_--){
solve();
}
return 0;
}
边栏推荐
- export , export default, import complete usage
- sql concat()函数
- RAID disk array
- Playing script killing with AI: actually more involved than me
- DP5340国产替代CM5340立体声音频A/D转换器芯片
- 入选“十大硬核科技”,详解可信密态计算(TECC)技术点
- 解决datagrip连接sqlserver报错:[08S01] 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。
- go : 使用gorm创建数据库记录
- Input method for programmers
- Proof of distance calculation from space vertex to plane and its source code
猜你喜欢
2020 数学建模之旅
RAID disk array
Boot process and service control
什么是微服务?
New breakthrough in artificial muscle smart materials
What happens when @Bean and @Component are used on the same class?
Is it possible to use the same port for UDP and TCP?
[硬核干货]由0到1,突破信息系统项目管理师(呕心沥血经验之谈)!!!
No, the Log4j vulnerability hasn't been fully fixed yet?
The calculation and source code of the straight line intersecting the space plane
随机推荐
Proof of distance calculation from space vertex to plane and its source code
开发常用工具软件
Goto statements
专访蚂蚁:这群技术排头兵,如何做好底层开发这件事?| 卓越技术团队访谈录
How to use Swagger, say goodbye to postman
Is it possible to use the same port for UDP and TCP?
Go 结合Gin导出Mysql数据到Excel表格
理解和熟悉递归中的尝试
《心智社会》—马文·明斯基
go : go gin returns JSON data
Go uses the mencached cache
适合程序员的输入法
Electron使用romote报错 : Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
sql concat()函数
go : go-redis 基础操作
The Geometric Meaning of Vector Cross Product and the Calculation of Modulus
The terminal connection tools, rolling Xshell
Graphical relational database design ideas, this is too vivid
【COCI 2020/2021 Round #2 D】Magneti(DP)
[硬核干货]由0到1,突破信息系统项目管理师(呕心沥血经验之谈)!!!