A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6)

那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10)

思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事。

但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y,

最大的左移到x,所以就是最大x-最小y完事

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,x,y,z,b,c=0,a=0,k;
ll arr[1000006];
int main()
{
ios_base::sync_with_stdio(0);
cin>>m;
while(m--){
cin>>n;
ll mx = -1e9 , mn=1e9;
for(int i=0 ; i<n;i++){
cin>>x>>y;
mx = max(mx , x);
mn = min(mn , y);
}
cout<<max(mx -mn , (ll) 0)<<endl;
}
return 0;
}

B 没啥好说的,

https://codeforces.com/contest/1262/problem/B

#include <cstdio>
#include <algorithm>
#include <set>
using namespace std; const int maxn = 1e5+10; int n, p[maxn], a[maxn];
set<int> s; void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a+i);
s.insert(i);
}
for (int i = 1; i <= n; ++i) {
if (a[i] != a[i-1]) {
p[i] = a[i];
s.erase(a[i]);
} else {
if (*s.begin() > a[i]) {
puts("-1");
return;
}
p[i] = *s.begin();
s.erase(s.begin());
}
}
for (int i = 1; i <= n; ++i)
printf("%d%c", p[i], " \n"[i==n]);
} int main() {
int t;
scanf("%d", &t);
while (t--) solve();
}

 C,

给你一个括号序列,你有一个操作,选定l,r,就可以反转他们,例如 1 2 3 4变成 4 3 2 1

最多n次操作,那就说明我们一定能构造成我们想要的序列

题目要求你把这个序列变成合法括号序列,同时!恰好有k个前缀是合法的。

很容易想到先构造k-1个()这种序列,这样()()(),然后后面把所有括号变成((()))这种

#include<bits/stdc++.h>
using namespace std;
int n,k;
string s;
void solve_swap(int x,int y){
while(x<y){
swap(s[x],s[y]);
x++,y--;
}
}
string get_str(int n,int k){
string tmp="";
for(int i=0;i<k-1;i++){
tmp+="(";
tmp+=")";
}
int len = n-tmp.size();
for(int i=0;i<len/2;i++){
tmp+="(";
}
for(int i=0;i<len/2;i++){
tmp+=")";
}
return tmp;
}
void solve(){
cin>>n>>k;
cin>>s;
vector<pair<int,int>>ans;
string final_str = get_str(n,k);
for(int i=0;i<s.size();i++){
if(s[i]!=final_str[i]){
for(int j=i+1;j<s.size();j++){
if(s[j]==final_str[i]){
solve_swap(i,j);
ans.push_back(make_pair(i+1,j+1));
break;
}
}
}
}
//cout<<s<<endl;
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<endl;
}
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
}

  D1,D2

https://www.cnblogs.com/hgangang/p/11648398.html更新到了里面

 

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3的更多相关文章

  1. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

    F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong ...

  2. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) E. Arson In Berland Forest 二分 前缀和

    E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every ce ...

  3. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心

    D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, ...

  4. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

    C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket ...

  5. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心

    B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) pos ...

  6. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题

    A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...

  7. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy

    //因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...

  8. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B Box

    #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int total; cin>>total; w ...

  9. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem

    //只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int ...

随机推荐

  1. Nginx安装echo模块echo-nginx-module

    https://github.com/openresty/echo-nginx-module 这个模块不包含在 Nginx 源码中,安装方法: 1. 首先下载模块源码:https://github.c ...

  2. windows安装apache+mysql+php

    文件打包下载,包括apache.mysql.php,地址如下: 链接: https://pan.baidu.com/s/1Mcm4OxJV45UWsktBycw7mQ 密码: dwy6 安装apach ...

  3. display:none和visibility:hidden两者的区别

    display与元素的隐藏 如果给一个元素设置了display: none,那么该元素以及它的所有后代元素都会隐藏,它是前端开发人员使用频率最高的一种隐藏方式.隐藏后的元素无法点击,无法使用屏幕阅读器 ...

  4. LNMP环境搭建(<=PHP7.2)

    目录 准备工作 安装wget 安装net-tools 安装vim 配置显示行号 关闭防火墙 安装Nginx 安装依赖 编译安装Nginx 配置环境变量 Systemd管理 安装MySQL 安装依赖 下 ...

  5. Vue ---- 组价 组件化 子传父 父传子

    目录 补充js的for循环: 组件 1.组件的分类: 2.组件的特点 3.创建局部组件 4.全局组件 二.组件化 一.组件传参父传子 二.组件传参:子传父 补充js的for循环: // for in遍 ...

  6. Oracle常用函数(略微少了点 不过是自己稍微整理的)

    DECODE ​ DECODE(value ,if 1, then 1,if 2,then 2, ....,else) ​ 解析: ​ if 条件=1 ​ return (value 1) ​ if条 ...

  7. SpringBoot微服务电商项目开发实战 --- 模块版本号统一管理及Redis集成实现

    上一篇文章总结了基于SpringBoot实现分布式微服务下的统一配置.分环境部署配置.以及服务端模块的分离(每一个提供者就是一个独立的微服务).微服务落地.Dubbo整合及提供者.消费者的配置实现.本 ...

  8. 精通awk系列(14):细说awk中的变量和变量赋值

    回到: Linux系列文章 Shell系列文章 Awk系列文章 awk变量 awk的变量是动态变量,在使用时声明. 所以awk变量有3种状态: 未声明状态:称为untyped类型 引用过但未赋值状态: ...

  9. 形如 T(n) = a * T(n/b) + f(n) 的时间复杂度计算方法

    形如 T(n) = a * T(n/b) + f(n) 的时间复杂度计算方法 有一种方法叫做主方法(Master method)是用来专门计算这种形式的时间复杂度的,方法具体如下: 下边举例进行说明: ...

  10. 针对上一篇prim最后的完善结果

    edge* Graph::prim(int cur) { if (cur >= this->vertexNum) { return NULL; } int *weight = new in ...