C. Mark and His Unfinished Essay

https://codeforces.com/contest/1705/problem/C

会卡long long,下面解法62ms过的,还是参考了dalao们的思路,发现这个思路是最最最清晰的;

学会一种新的定义long long 的方法:定义#define int long long 然后signed main()

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 100
#define int long long
#define FA ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
int n,m,c,q;
int l[N],r[N],lc[N],rc[N];//l[],r[] is 复制的区间
//lc[],rc[] is 复制完的新位置signed main()
{int t;FA;cin>>t;while(t--){cin>>n>>c>>q;string s;cin>>s;int len=s.size();for(int i=1;i<=c;i++){//第i次的复制区间,总共C次复制,c个区间 cin>>l[i]>>r[i];int newlen=r[i]-l[i]+1;//更新复制到的区间位置 lc[i]=len+1;//在现在尾位置后面粘贴 rc[i]=lc[i]+newlen-1;len+=newlen;//更新现在的串长度 }while(q--){int k;cin>>k;//回去找原位置的字符//从最后一个区间开始向前找 for(int i=c;i>=1;i--){//现在看看k是在哪个区间里,用该区间的l[],r[],lc[],rc[]算原位置 if(lc[i]<=k && k<=rc[i]){k=k-lc[i]+l[i];//k-lc[该区间]==k数在该区间的位序//l[i]为现在这个区间对于原区列的首位置//加上l[i]就是该数字在原区间的序号。 }}cout<<s[k-1]<<endl; } }return 0;} 

D. Mark and Lightbulbs

https://codeforces.com/contest/1705/problem/D

#include<stdio.h>
#include<iostream>
#include<algorithm>
#define ll long long
#include<vector>
using namespace std;int main()
{int t;cin>>t;while(t--){int n;cin>>n;string a,b;cin>>a>>b;vector<ll> aa,bb;//存下a,b序列中的连续的块 if(a[0]==b[0] && a[n-1]==b[n-1]){for(int i=0;i<n-1;i++){if(a[i]!=a[i+1])//计算连续的块 aa.push_back(i);if(b[i]!=b[i+1])bb.push_back(i);}if(aa.size()==bb.size())//看连续的块相同否 {int num=aa.size();ll cnt=0;for(int i=0;i<num;i++){cnt+=abs(aa[i]-bb[i]);//a中1移动到b相应位置的距离 }cout<<cnt<<endl;}else//不相同则永远没有办法变成一样 cout<<"-1"<<endl;}else{cout<<"-1"<<endl;}}return 0;
}

Codeforces Round #807 (Div. 2)补题相关推荐

  1. Codeforces Round #723 (Div. 2)补题

    水题,只需要将序列分成两部分即可,一部分是大的,一部分是小的. #include <cstdio> #include <iostream> #include <algor ...

  2. Codeforces Round #702 (Div. 3)补题

    题目链接 文章目录 A. Dense Array B. Balanced Remainders C. Sum of Cubes D. Permutation Transformation E. Acc ...

  3. Codeforces Round #787 (Div. 3)补题

    目录: 官网链接 E. Replace With the Previous, Minimize F. Vlad and Unfinished Business G. Sorting Pancakes ...

  4. Codeforces Round #807 (Div. 2) A-C题解

    Codeforces Round #807 (Div. 2) A.B.C题题解 A - Mark the Photographer 题意:马克要给2n个人照相,分两排,一排站n人,给出每个人的身高,要 ...

  5. Codeforces Round #807 (Div. 2) A-D

    Codeforces Round #807 (Div. 2) A. Mark the Photographer 给定整数n,数组长度2*n,问能不能拆成两个长度为n的数组,两个数组的第i项有a[i]& ...

  6. Codeforces Round #807 (Div. 2)A~E个人题解

    Dashboard - Codeforces Round #807 (Div. 2) - Codeforces A. Mark the Photographer 题意: 有个人,每个人的身高设为,现在 ...

  7. Codeforces Round #807 (Div. 2)(A-D)

    Dashboard - Codeforces Round #807 (Div. 2) - CodeforcesCodeforces. Programming competitions and cont ...

  8. Codeforces Round #807 (Div. 2) A - D

    Codeforces Round #807 (Div. 2) 提交情况 参考 Codeforces Round #807 (Div. 2) A~E A. Mark the Photographer 标 ...

  9. Codeforces Round 700 (Div. 2) B题 英雄杀怪兽

    Codeforces Round 700 (Div. 2) B题 链接: https://codeforces.com/contest/1480/problem/B 大致意思: n组数据,每组数据的第 ...

最新文章

  1. 硬件手册里经常出现的assert以及deassert
  2. 离散数学关系的基本运算和关系的性质闭包
  3. redmine2.4.2 插件安装
  4. html 注册插件,HTML 插件
  5. 数组转换成json key-value形式
  6. 深度学习激活函数总结
  7. 给定一个数组 a[n], 输出b[n], 其中 b[i] = a[0]*a[1]...*a[i-1]*a[i+1]*....a[n]; 其中不能用除法 复杂度要求O(n)...
  8. 描述 J2EE 框架的多层结构,并简要说明各层的作用。
  9. 密码编码学与网络安全-------原理与实践(第七版)
  10. 顶级域名 一级域名 二级域名 三级域名划分
  11. Spring Boot入门教程(四):配置文件
  12. 数据结构之线性表----一文看懂顺序表、单链表、双链表、循环链表
  13. 程序员 大牛 面试
  14. Chrome油猴(Tampermonkey)脚本使用及常用脚本分享
  15. 通过Gartner 2018年新兴技术成熟度曲线解读大数据人工智能技术的发展
  16. [翻译]ASP.NET MVC4新特性之脚本压缩和合并
  17. CVE-2022-40684 Fortinet(飞塔)身份验证绕过漏洞
  18. win10卸载软件 管理员已阻止你运行此应用的提示
  19. 触发器与存储过程的区别
  20. c语言--输入字符大写转小写,小写转大写

热门文章

  1. 这10种神级性能优化手段,你用过几个?
  2. 区块链:Hyperledger Fabric环境配置及fabric-sample测试运行
  3. Docker与微服务实战2022:基础篇
  4. python np.random.seed直观程序理解
  5. fpga实现dds和混频器
  6. J-LinK-OB改造版 仿真/调试器 使用说明
  7. SOLIDWORKS 切割清单默认模板、内容丢失问题
  8. 基于神经网络 lstm的股票开盘价收盘价预测详细
  9. 项目上线后,接口报错:SELECT command denied to user ‘用户名’ @ localhost‘ for table ‘ ‘
  10. ITSS资质办理流程是什么?