Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3
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的更多相关文章
- 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 ...
- 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 ...
- 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, ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C Messy
//因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> us ...
- 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 ...
- 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 ...
随机推荐
- css3(1)
边框: 盒子圆角:border-radius:5px / 20%: border-radius:5px 4px 3px 2px; 左上,右上,右下,左下. 盒子阴影: box-shadow: box- ...
- 【MobX】391- MobX 入门教程(下)
点击上方"前端自习课"关注,学习起来~ 三.MobX 常用 API 介绍 3. 修改可观察数据 在上一部分内容中,我们了解到,对可观察的数据做出反应的时候,需要我们手动修改可观察数 ...
- 大数据学习笔记——Java篇之网络编程基础
Java网络编程学习笔记 1. 网络编程基础知识 1.1 网络分层图 网络分层分为两种模型:OSI模型以及TCP/IP网络模型,前者模型分为7层,是一个理论的,参考的模型:后者为实际应用的模型,具体对 ...
- 大数据项目2(Java8聚合操作)
前言:为很好的理解这些方法,你需要熟悉java8特性Lambda和方法引用的使用 一:简介 我们用集合的目的,往往不是简单的仅仅把数据保存哪里.而是要检索(遍历)或者去计算或统计....操作集合里面的 ...
- NodeJS2-5环境&调试----process(进程)
argv(参数相关的) /* argv argv0 execArgv execPath */ const { argv, argv0, execArgv, execPath } = process; ...
- this的绑定(四种绑定)+ 箭头函数 的this
一.this的默认绑定 当一个函数没有明确的调用对象的时候,也就是单纯作为独立函数调用的时候,将对函数的this使用默认绑定:绑定到全局的window对象 例子1: function foo(){ c ...
- super()派生使用中的常见两个错误
""" super()派生可以继承父类的属性 --super()派生继承父类的语法是:super().__init__() --super().__init__()中的_ ...
- 安卓逆向基础(002)-android虚拟机
一, android分两种 1.Android 5.0以下(不含5.0) dalvik字节码 为dalvik虚拟机(jit机制) 基于寄存器架构 .dex=>dexopt=>.odex d ...
- 运用Java调用Kettle Job和Trans(带参数)
1.首先创建一个kettle trans 2.对表输入进行编辑 ${dateNow}为要传入的参数. 3.代码编写 首先需要把包导入 import org.pentaho.di.core.Kettle ...
- 使用keepalived做High Available(HA)
原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/eab34383-d ...