当前位置:网站首页>【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;
}
边栏推荐
- Upload file -- file type, picture type, document type, video type, compressed package type
- 包含min函数的栈(js)
- The calculation of the determinant of the matrix and its source code
- A magical no main method of code
- Ali: How many methods are there for multi-threaded sequential operation?
- Is it possible to use the same port for UDP and TCP?
- 预测人们对你的第一印象,“AI颜狗”的诞生
- window.open()的用法,js打开新窗体
- Keil编译大小和存储说明
- ArrayList
猜你喜欢

Go 使用mencached缓存

PXE efficient mass network capacity

便携小风扇PD取电芯片

Ali two sides: Sentinel vs Hystrix comparison, how to choose?

Redis 如何实现防止超卖和库存扣减操作?

From catching up to surpassing, domestic software shows its talents

DP5340国产替代CM5340立体声音频A/D转换器芯片

和AI一起玩儿剧本杀:居然比我还入戏

Electron之初出茅庐——搭建环境并运行第一个程序

云服务器零基础部署网站(保姆级教程)
随机推荐
AI can identify race from X-rays, but no one knows why
go : 使用gorm修改数据
go : delete database data using grom
Go 使用mencached缓存
No, the Log4j vulnerability hasn't been fully fixed yet?
Huawei released "ten inventions", including computing, intelligent driving and other new fields
LVM and disk quotas
golang: Gorm configures Mysql multiple data sources
分布式系统中的开创者—莱斯利·兰伯特
Develop common tool software
Pioneer in Distributed Systems - Leslie Lambert
《心智社会》—马文·明斯基
go : go-redis list操作
Hex conversion...
深度学习:线性回归模型
go : 使用 grom 删除数据库数据
Station B collapsed, what would you do if you were the developer in charge that night?
golang: Gorm配置Mysql多数据源
New material under the plastic restriction order - polylactic acid (PLA)
进制转换。。。