HDU-6668-Game 百度之星第一场B
2024-10-08 04:03:08
在多个连续的区间段中,选出连续重复度最高的区间,这样连续选出多个重复度最高的不相交区间,然后从第一个区间的左边已经右边开始,连续贪心即可,答案取最小值
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<vector>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define LL long long
using namespace std;
vector<pii>v;
const int maxx = ;
int a[maxx];
int b[maxx];
int n;
LL go(int x){
LL ans=;
for(int i=;i<v.size();i++){
if (v[i].first>x){
ans+=(v[i].first-x+)/;
if (i<v.size()-){
if ((v[i].first-x)%){ ///长度为奇数
if (v[i+].first>v[i].second && v[i].second-v[i].first>){
x=v[i].first+;
}else x=v[i].first;
}else x=v[i].first;
}else x=v[i].first;
}else {
ans+=(x-v[i].second+)/;
if (i<v.size()-){
if ((x-v[i].second)%){
if(v[i+].second<v[i].first && v[i].second-v[i].first>){
x=v[i].second-;
}else x=v[i].second;
}else x=v[i].second;
}else x=v[i].second;
}
}
return ans;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
v.clear();
scanf("%d",&n);
scanf("%d%d",&a[],&b[]);
int l=a[],r=b[];
for (int i=;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
if (a[i]<=r && b[i]>=l){
l=max(l,a[i]);
r=min(r,b[i]);
}else {
v.pb(mp(l,r));
l=a[i];
r=b[i];
}
}
v.pb(mp(l,r));
LL ans=2e18;
ans=min(ans,go(v[].first));
ans=min(ans,go(v[].second));
printf("%lld\n",ans);
}
return ;
}
最新文章
- 重温Http协议--请求报文和响应报文
- 简单说下COALESCE这个日常使用的函数
- react+redux官方实例TODO从最简单的入门(6)-- 完结
- mysql 字符串 日期互转
- log4net 自定义Layout日志字段
- Storm 单机版环境搭建
- JQUERY MOBILE 中文API站 和 官方论坛
- 【JDK源码分析】String的存储区与不可变性
- Android中Bitmap和Drawable
- mongoose学习文档
- java适配器模式随笔记
- HDU4349--Xiao Ming&#39;s Hope(数论)
- Android 2D绘图初步
- HDU 3078 Network LCA
- 读《不要告诉我你懂margin(海玉的博客)》有感
- php多个文件上传
- .NET开发一个微信跳一跳辅助程序
- npm 设置和取消代理配置
- c#mvc实现登录
- leetcode — container-with-most-water
热门文章
- 关系数据库理论 ch.6
- python 变量离散化
- Leetcode669.Trim a Binary Search Tree修建二叉树
- git出现“The file will have its original line endings in your working directory”错误
- 运行Jmeter时,响应数据中文乱码问题解决办法
- SCAN listener and Node listener – How does it work
- docker容器时区问题
- 【水滴石穿】React Native 组件之SafeAreaView
- 从 Program Manager 看 Leader 是什么角色
- Pycurl介绍