博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cake Robbery
阅读量:4477 次
发布时间:2019-06-08

本文共 2690 字,大约阅读时间需要 8 分钟。

Cake Robbery
Time Limit: 2000 msMemory Limit: 65536 KB

As usual, Alice finishes her delicious cake at noon. Unfortunately, the smell of cake beckoned hungry Bob, and he decided to rob one piece of cake.

The cake is a convex polygon with N edges. At the beginning, Bob cut it along the diagonals. After M cuts, Bob decided to rob the 'largest' piece of cake. Strangely, in Bob's opinion, the piece has the most number of edge is the biggest one.

Please help Bob to find the 'largest' piece.

Input

There are multiple test cases (about 20).

The first line of each test case contains two integer number NM (5 <= N <= 10000), indicating the number of point of the cake and the cut, respectively.

The following M lines contain two integer x, y (1 <= x, y <= N), denoting the index of the starting and ending cut point. (the index of points mark from 1 to Nclockwise.)

The input will guarantee that all of the cuts will not intersect inside the cake, but they may cross each other at the edge of cake, and Bob won't cut along the initial edge of the cake.

Output

Output the maximal size (most number of edges) of the piece which Bob will get.

Sample Input

7 23 67 2

Sample Output

4
#include
using namespace std;typedef long long ll;const int maxn = 2e5 + 50;struct cake { int l, r; inline void get() { scanf("%d%d", &l, &r); if (l > r)swap(l, r); } bool operator<(const cake &cur) const { return r - l + 1 <= cur.r - cur.l + 1; }} o[maxn];struct tree { int l, r, cnt;} e[maxn];inline void build(int rt, int l, int r) { e[rt].l = l; e[rt].r = r; e[rt].cnt = r - l + 1; if (l == r)return; int mid = l + r >> 1; build(rt << 1, l, mid); build(rt << 1 | 1, mid + 1, r);}inline void update(int ql, int qr, int rt) { int l = e[rt].l; int r = e[rt].r; if (ql <= l && qr >= r) { e[rt].cnt = 0; return; } int mid = l + r >> 1; if (ql <= mid) { update(ql, qr, rt << 1); } if (qr > mid) { update(ql, qr, rt << 1 | 1); } e[rt].cnt = e[rt << 1].cnt + e[rt << 1 | 1].cnt;}int n, m;int main() {#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif while (scanf("%d%d", &n, &m) != EOF) { for (register int i = 1; i <= m; ++i) { o[i].get(); } sort(o + 1, o + 1 + m); build(1, 1, n); int res = 0, tot = e[1].cnt; for (register int i = 1; i <= m; ++i) { update(o[i].l + 1, o[i].r - 1, 1); res = max(res, tot - e[1].cnt + 2); tot = e[1].cnt; } res = max(res, e[1].cnt); printf("%d\n", res); } return 0;}

 

转载于:https://www.cnblogs.com/czy-power/p/11487982.html

你可能感兴趣的文章
php 实现设计模式之 建造者模式
查看>>
An Easy C Program Problem
查看>>
Replace Nested Conditional with Guard Clauses(用卫语句代替嵌套循环)
查看>>
jsp中${}是EL表达式的常规表示方式
查看>>
GoldenGate常见问题及处理
查看>>
Android JNI学习(五)——Demo演示
查看>>
SSRS 呈现Barcode Free
查看>>
java快速排序引起的StackOverflowError异常
查看>>
泛函编程(35)-泛函Stream IO:IO处理过程-IO Process
查看>>
-XX:-PrintClassHistogram 按下Ctrl+Break后,打印类的信息
查看>>
mac 安装php redis扩展
查看>>
css3中Animation
查看>>
JS 判断是否是手机端并跳转操作
查看>>
最短路径问题(dijkstra-模板)
查看>>
c# 导出表格 api
查看>>
使用Android NDK以及JNI编写应用
查看>>
学习笔记之-php数组数据结构
查看>>
初学者--bootstrap(六)组件中的下拉菜单----在路上(10)
查看>>
QMetaObject::connectSlotsByName 总结
查看>>
app图标
查看>>