题意

题目链接

Sol

不会正解

写了发暴力过了,貌似跑的还挺快?。。

// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define LL long long
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 8e5 + 10, INF = 1e9;
const double eps = 1e-5;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, a[MAXN], b[MAXN], col[MAXN], out, x, y, gg = INF, ti[MAXN], ss, st[MAXN], top;
int solve(int l, int r) {
ss++;
int ans = 0;
for(int i = l; i <= r; i++) {
if(ti[col[i]] != ss) ti[col[i]] = ss;
else ans++, ss++;
if(ans >= out) return out;
}
return ans;
}
signed main() {
N = read();
for(int i = 1; i <= N; i++) {
a[i] = read(), b[i] = read();
if(a[i] > b[i]) swap(a[i], b[i]);
col[a[i]] = col[a[i] + 2 * N] = i;
col[b[i]] = col[b[i] + 2 * N] = i;
int tmp = min(b[i] - a[i], a[i] - b[i] + 2 * N);
if(tmp < gg) x = a[i], y = b[i], gg = tmp;
}
out = INF;
for(int i = x; i <= y; i++) st[++top] = i;
random_shuffle(st + 1, st + top + 1);
for(int i = 1; i <= top; i++) {
int k = st[i];
chmin(out, solve(k, k + 2 * N - 1));
}
cout << out / 2 +1;
return 0;
}

最新文章

  1. Mysql与Oracle区别
  2. git push error: A Contributor Agreement must be completed before uploading
  3. 为什么没有MMU的处理器无法安装操作系统?
  4. 使用Android Studio打Andorid apk包的流程
  5. Redis常用命令汇总
  6. Sql Server数据库
  7. 如何在Windows系统上用抓包软件Wireshark截获iPhone等网络通讯数据
  8. win7上帝模式
  9. 观看网上的N多教程有感
  10. 使用JsonConfig控制JSON lib序列化
  11. Ubantu 16.4 samba安装配置
  12. [编织消息框架][JAVA核心技术]动态代理介绍
  13. 服务注册中心之ZooKeeper系列(二) 实现一个简单微服务之间调用的例子
  14. 【iCore4 双核心板_ARM】例程三十七:SDRAM实验——读写SDRAM
  15. springcloud学习计划
  16. 《Linux内核设计与实现》第八周读书笔记——第四章 进程调度
  17. codeforces 777C
  18. C# 递归缩小图片
  19. SoapUI使用笔记备忘
  20. cmd.exe_参数_启动参数 cmd加启动运行参数 命令

热门文章

  1. H5的Web Audio Api
  2. JavaScript 作用域、命名空间及闭包
  3. 几个java小例子
  4. python 安装 reportlab 报错 “ImportError: No module named reportlab.lib”
  5. PostgreSQL踩坑现场
  6. Github page搭建博客使用自定义插件的方法
  7. 微信支付之手机H5支付实践
  8. mysql中外键的特点
  9. 高性能Mysql笔记 — 索引
  10. JavaScript之ECMA对象的学习