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. python读取,显示,保存mnist图片

    python处理二进制 python的struct模块可以将整型(或者其它类型)转化为byte数组.看下面的代码. # coding: utf-8 from struct import * # 包装成 ...

  2. 【数据结构05】红-黑树基础----二叉搜索树(Binary Search Tree)

    目录 1.二分法引言 2.二叉搜索树定义 3.二叉搜索树的CRUD 4.二叉搜索树的两种极端情况 5.二叉搜索树总结 前言 在[算法04]树与二叉树中,已经介绍过了关于树的一些基本概念以及二叉树的前中 ...

  3. 《项目实战》从Spring开始说起

    引导 从今天开始,我们正式进入项目实战系列,我们会从项目架构的搭建,以及如何解决三高问题(高并发.高可用.高性能),源码会同步进行更新,欢迎大家持续关注 https://gitee.com/liupa ...

  4. 谈一谈AOP面向切面编程

    AOP是什么 : AOP面向切面编程他是一种编程思想,是指在程序运行期间,将某段代码动态的切入到指定方法的指定位置,将这种编程方式称为面向切面编程 AOP使用场景 : 日志 事务 使用AOP的好处是: ...

  5. JMeter之SteppingShape

    1.背景 其实是这样的,最近包括以前都有同事问过宝路一个问题:JMeter测试计划中涉及到梯度压测时,整个测试计划执行完毕,聚合报告看的是整体的结果啊!并不能直观看到每个梯度下的吞吐量的值(虽然可以通 ...

  6. LNMP-Nginx负载均衡

    Nginx负载均衡介绍 Nginx提供负载均衡的模块upstream,这个模块是默认的,不需要重新编译模块.通常情况下,负载均衡一般用于后端两台机器同时提供服务供用户访问,但是用户经常访问的其中一台服 ...

  7. iview表单验证trigger:'change,blur'

    今天发现,如果设置select的trigger:'blur'就算选择之后还是边框是红色的,之后查了一下iview的文档,也没有找到准确的蚊子描述,只看到form那个组件其中有一个例子,大概是selec ...

  8. hdu 6318 Swaps and Inversions (线段树求逆序对数)

    Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. cookie与session django中间件

    目录 一.什么是cookie 二.django中操作cookie 2.1 如何操作cookie 2.2 操作cookie 三.什么是session 四.django中操作session 4.1 创建c ...

  10. Spring Cloud Config入门(本地配置)

    spring cloud config 简介 Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外 ...