Codeforces Round #535 (Div. 3)
E:
题意:
给出n个整数ai和m个区间[li,ri] 你可以选择一些区间,并且将区间内的数字都减一。你要选择一些区间,然后使得改变后的数列中maxbi-minbi的值最大。
题解:
假设我们已经知道了这n个数中最大值的位置pmax,和最小值的位置pmin,那么对于一个区间[li,ri],有三种情况。
1.如果pmax和pmin在区间[li,ri]内,那么这个区间加不加都对答案没有贡献。
2.如果pmin在区间内pmax不在区间内,那么这个区间加上对答案的贡献就为1
3.如果pmax在区间内pmin不在区间内,那么加上这个区间对答案的贡献为-1.
所以我们发现,只要pmin在区间内的区间,选上它答案一定不会变的更差。
那么n*m的复杂度就可以解决这个问题了,将区间按照左区间排序,从1到n扫,当前i为某个区间的开始或者结束点的时候,更新和消除影响。
F:
题意:
给出n个点和m条边,没有重边和自环。问你最少要给多少条边的权值+1使得MST不变且唯一。
题解:
我们定义一下冲突边:存在一些边,权值都是当前都小的,且只能从这里面选一条边加入MST,即,原本他们都能加入MST,但是加入一条以后剩余的都没法加入MST了。
对于所有的冲突边,选一条加入MST,然后其他边的权值都要+1.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
const int maxn=2e5+;
struct Edge{
int from,to,w;
bool operator<(const Edge& rhs)const{
return w<rhs.w;
}
}edges[maxn];
int n,m;
int p[maxn];
int find(int x){
return p[x]==x?x:p[x]=find(p[x]);
} int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)p[i]=i;
for(int i=;i<=m;i++)
scanf("%d%d%d",&edges[i].from,&edges[i].to,&edges[i].w);
sort(edges+,edges++m);
int ans=;
for(int i=;i<=m;){
int j=i;
while(edges[j].w==edges[i].w){
j++;
}
j--;
int num=;
for(int k=i;k<=j;k++){
int x=find(edges[k].from);
int y=find(edges[k].to);
if(x!=y)
num++;
}
for(int k=i;k<=j;k++){
int x=find(edges[k].from);
int y=find(edges[k].to);
if(x!=y){
p[x]=y;
num--;
}
}
ans+=num;
i=j+;
}
printf("%d\n",ans);
return ;
}
Codeforces Round #535 (Div. 3)的更多相关文章
- Codeforces Round #535 (Div. 3) 题解
Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...
- Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...
- Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]
hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #535 (Div. 3) 解题报告
CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...
- Codeforces Round #535 (Div. 3) 1108C - Nice Garland
#include <bits/stdc++.h> using namespace std; int main() { #ifdef _DEBUG freopen("input.t ...
- Codeforces Round #535(div 3) 简要题解
Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...
- Codeforces Round #535 (Div. 3) F
F. MST Unification 题目传送门 题意: 给你n个顶点,m条边:保证没有重边,其中存在多个MST(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...
随机推荐
- ES之六:ElasticSearch中Filter和Query的异同
如下例子,查找性别是女,所在的州是PA,过滤条件是年龄是39岁,balance大于等于10000的文档: { "query": { "bool": { &quo ...
- 学习URL地址(待整理)
编程开发教程:http://www.runoob.com/ ElasticSearch教程:https://es.xiaoleilu.com/index.html 设计模式:http://www.cn ...
- skopt超参数优化实例
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_boston from skl ...
- ESB的编程模型(场景)
GateWay:网关channel:数据传输的通道adapter:数据连接通道的数据适配器spliter:对通道里面的数据进行分割router:对通道进行路由transforme:对消息进行格式化转化 ...
- php trim() 函数实例讲解
php trim() 函数移除字符串两侧的空白字符或其他预定义字符,本文章向码农介绍php trim() 函数的使用方法和实例,感兴趣的码农可以参考一下. 定义和用法 trim() 函数移除字符串两侧 ...
- sencha touch 小米3无法点击问题 修复
修改源码文件夹下event/publisher/Dom.js中的attachListener方法,代码如下 attachListener: function(eventName, doc) { if ...
- css3网站收集
把群里大家推荐的网站做了下收集,等有时间了研究下 1.http://icomoon.io/app/ 这个网站用来生成跟导出字体图标的,自带的图标种类很多很丰富,基本够用了,不过你也可以自己设计,然后 ...
- Python分页转Mybatis pagehelper格式分页
最近工作里遇到一个需求要把之前用Java写的一个http接口替换成用Python写的,出参是带了mybatis pageHelper中PageInfo信息的一个JSON串,而Python这边分页不会涉 ...
- CYQ.Data 批量添加数据性能测试(每秒千、万)---003
原文地址:https://www.cnblogs.com/cyq1162/p/3216267.html 今天有网友火晋地同学进了CYQ.Data官方群了,他正在折腾了一个各大ORM性能测试的比较的软件 ...
- selenium+python自动化89-用例不通过的时候发送邮件
前言 实现需求:当测试用例全部通过的时候,不发邮件,当用例出现Error或Failure的时候发送邮件 解决思路:生成html测试报告后,用bs4解析html页面,写个函数判断页面上是都有不通过的记录 ...