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 ...
随机推荐
- k8s 开船记-修船:改 readinessProbe ,去 DaemonSet ,上 Autoscaler
(图片来自网络) 改 readinessProbe 对于昨天 k8s 尼克号发生的触礁事故,我们分析下来主要是2个原因,一是当时4个节点不够用造成部分容器负载过高而宕机,二是 readinessPro ...
- Appium之选择/操作元素
Appium是如何选择.操作元素的呢? appium自动化 ------ 选择界面 元素 操作元素 ------- ① 点击 ② 输入字符 ③ 拖拽 ④ 获取页面元素的各种属性 根据appium ...
- linux—chmod
chmod -options -c 只输出被改变的文件信息 -f , --silent, --quite 当chmod不能改变文件模式时,不通知用户 -R 递归 ...
- 【CSS】340- 常用九宫格布局的几大方法汇总
对,就是类似这样的布局~ 目录 1 margin负值实现 2 祖父和亲爹的里应外合 3 换个思路 - li生个儿子帮大忙 4 借助absolute方位值,实现自适应的网格布局 5 cloumn多 ...
- Python递归函数如何写?正确的Python递归函数用法
前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归 ...
- Python异常体系结构图
- CCF-CSP题解 201809-4 再卖菜
碎碎念..近视加老花,还以为第二天除了第二家范围在100以内别的都不确定,于是x**算的记搜复杂度超时了.还鼓捣着什么差分区间最长路,虽然有大神用差分区间做出来了,然而自己并没有看懂. 其实就是一个记 ...
- Mybatis中的 >= <= 与 sql写法区别
- Android开发模版代码(4)——状态栏设置
下面的代码是基于开源项目SystemBarTint,我们需要添加其依赖 compile 'com.readystatesoftware.systembartint:systembartint:1.0. ...
- Java面试题_第一阶段(static、final、面向对象、多线程、集合、String、同步、接口、GC、JVM)
1.1 简述static和final的用法? static:修饰属性,方法,代码块 (1)静态属性:也可叫类变量 类名.属性名 来访问 (共有的类变量与对象无关,只和类有关) 注意:类中的实例变量 ...