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. MT9V034 全局快门体验总结

    MT9V034 全局快门体验总结 部分照片来源网络,尊重版权. . 这个是实物照片 全局快门(相对滚动快门) 拍摄高速物体的效果 高动态效果 低照度和高照度对比 实际拍照效果图(来自网友华健) 特殊应 ...

  2. 从RTL视图到Verilog语言-转可乐豆原创

    从RTL视图到Verilog语言 曾经听过某位大牛都说:“当你的学习FPGA到一个境界的时候,你看到的硬件描述语言,将不再是单纯的语言,而是由一个个逻辑门组成的电路图,一旦达到这个境界,方能把代码写到 ...

  3. 非线性函数的最小二乘拟合及在Jupyter notebook中输入公式 [原创]

    突然有个想法,能否通过学习一阶RC电路的阶跃响应得到RC电路的结构特征——时间常数τ(即R*C).回答无疑是肯定的,但问题是怎样通过最小二乘法.正规方程,以更多的采样点数来降低信号采集噪声对τ估计值的 ...

  4. Scala函数式编程(四)函数式的数据结构 下

    前情提要 Scala函数式编程指南(一) 函数式思想介绍 scala函数式编程(二) scala基础语法介绍 Scala函数式编程(三) scala集合和函数 Scala函数式编程(四)函数式的数据结 ...

  5. ssh jail

    useradd -s /sbin/nologin -M updateuserpasswd updateusermkdir /home/updatechown root:root /home/updat ...

  6. MongoDB 快速扫盲贴

    长话短说 经过996的历练,开发者潜意识里总是以object的视角看待事物, 现在某些数据库也具备这样的视角. MongoDB是一个文档型(类JSON 文档)数据库,相比传统的关系型row/colum ...

  7. spring boot2 修改默认json解析器Jackson为fastjson

    0.前言 fastjson是阿里出的,尽管近年fasjson爆出过几次严重漏洞,但是平心而论,fastjson的性能的确很有优势,尤其是大数据量时的性能优势,所以fastjson依然是我们的首选:sp ...

  8. C#线程学习笔记十:async & await入门三

    一.Task.Yield Task.Yield简单来说就是创建时就已经完成的Task,或者说执行时间为0的Task,或者说是空任务,也就是在创建时就将Task的IsCompeted值设置为0. 我们知 ...

  9. MongoDB安装与Spring整合

    MongoDB是面向文档的非关系型数据库,数据模型是一种类似于JSON的结构,在数据库中存的是各种各样的JSON.官网下载地址:https://www.mongodb.com/download-cen ...

  10. Ubuntu : apt 命令

    apt 命令是一个功能强大的命令行工具,它不仅可以更新软件包列表索引.执行安装新软件包.升级现有软件包,还能够升级整个 Ubuntu 系统(apt 是 Debian 系操作系统的包管理工具).与更专业 ...