当前位置:网站首页>Codeforces Round #807 (Div. 2)
Codeforces Round #807 (Div. 2)
2022-07-26 04:30:00 【why151】
C:Mark and His Unfinished Essay
题目描述:
给定一个字符串,每次截取al-ar添加到a的后边,随后又q个询问,问第i个字符是什么?
主要思路:
将k递归到原字符上的位置,然后进行输出。
直接向后添加肯定会长度超限的,所以肯定是想办法递归到最初字符串的位置上。
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll l[N],r[N],book[N];
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,c,q;
cin>>n>>c>>q;
string s;
cin>>s;
l[0]=0;
r[0]=n;// 存储后一个的位置
for(int i=1;i<=c;i++)
{
ll ll,rr;
cin>>ll>>rr;
ll--;
rr--;
l[i]=r[i-1];
r[i]=l[i]+rr-ll+1;
// 标记当前位置是从之前的哪个位置复制过来的
book[i]=l[i]-ll;
}
while(q--)
{
ll k;
cin>>k;
k--;
// 依次向后推
for(int i=c;i;i--)
{
if(k<l[i]) continue;
else
k-=book[i];
}
cout<<s[k]<<endl;
}
}
return 0;
}
D:Mark and Lightbulbs
题目描述:
有n个灯泡,用n位的二进制串表示n个灯泡的开关情况。
给出灯泡现在的开关情况以及灯泡的目标情况。
问能否通过操作:
实现目标,最少需要操作多少次。
主要思路:
通过题目给出的操作条件可以看出来,(这里将连续相同的状态看作是一个块)对于一个块来说,只能改变块两边灯泡的开关状态,而不能改变块内部的状态,所以首先两个状态的块数应该相同。
注意,首尾没有办法改变!
标记每个块的位置信息,一个1块变化一个边界需要操作一次
标记全部01块的右边界(因为0块的右边界是1块的左边界)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
vector<int> aa,bb;
typedef long long ll;
int main()
{
int t;
cin>>t;
while(t--)
{
aa.clear();
bb.clear();
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
// 首尾没有办法改变,如果不同的话就-1
if(s1[0]!=s2[0]||s1[n-1]!=s2[n-1])
{
cout<<-1<<endl;
continue;
}
// 标记每个块的位置信息,一个1块变化一个边界需要操作一次
// 标记全部01块的右边界(因为0块的右边界是1块的左边界)
for(int i=0;i<n-1;i++)
{
if(s1[i]!=s1[i+1]) aa.push_back(i);
if(s2[i]!=s2[i+1]) bb.push_back(i);
}
if(aa.size()!=bb.size())
{
cout<<-1<<endl;
continue;
}
ll ans=0;
for(int i=0;i<aa.size();i++)
{
ans+=abs(aa[i]-bb[i]);
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- 十一、异常处理器
- 11、 Exception handler
- Phaser(一):平台跳跃收集游戏
- Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
- How to make your language academic when writing a thesis? Just remember four sentences!
- Which websites can I visit to check the latest medical literature?
- How is the launch of ros2 different?
- 支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
- FFmpeg 视频编码
- Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
猜你喜欢
随机推荐
七、RESTful
计算离散点的曲率(matlab)
Apisex's exploration in the field of API and microservices
MySQL的优化分析及效率执行
2022河南萌新联赛第(三)场:河南大学 B - 逆序对计数
一、基础入门
[learning notes] agc041
How does win11 change the power mode? Win11 method of changing power mode
机器学习之桑基图(用于用户行为分析)
Acwing_ 12. Find a specific solution for the knapsack problem_ dp
Steam science education endows classroom teaching with creativity
Yadi started to slow down after high-end
RTSP/Onvif协议视频平台EasyNVR服务一键升级功能的使用教程
MySQL only checks the reasons for the slow execution of one line statements
qt编译报错整理及Remote模块下载
人脸数据库收集总结
UE4 获取玩家控制权的两种方式
数组排序2
Solution: runtimeerror: expected object of scalar type int but got scalar type double
MySQL usage









