ZOJ 3511 不相交切切多邊形 線段樹求最大邊數

來源:互聯網
上載者:User

九野的部落格,轉載請註明出處:http://blog.csdn.net/acmmmm/article/details/12070909

題意:

n多凸邊形 m刀 (把n切m刀,問切完後的圖形中 最多的邊數 是多少)

切a點-b點

資料保證切的刀不會相交

思路:

2點之間的剩餘點數就是邊數,

把a-b距離 近 排序

切完一刀就統計一下切出來的蛋糕的邊數,並捨棄

[a,b] 表示a,b 點間剩下的點數(就是邊數)

先計算[a,b]的點數, 然後刪除(a,b) 區間的點 (注意刪除的是(a,b) ,所以實際操作是 刪除[a,b] )

 

最後要特殊算下 剩下那塊的(因為那塊沒有切)

 

#include<iostream>#include<stdio.h>#include<string>#include<string.h>#include<algorithm>#include<set>#include <cstdio>  #include <cstring>  #include <iostream>  #include <math.h>  #include <queue>  #define N 10100  #define M 2000100  #define inf64 0x7ffffff  #define inf 1073741824  #define ll int  #define L(x) x<<1  #define R(x) x<<1|1  #define Mid(x,y) (x+y)>>1  using namespace std;  inline ll Min(ll a,ll b){return a>b?b:a;}  inline ll Max(ll a,ll b){return a>b?a:b;}    struct Point{int x,y,dis;}p[N];bool cmp(Point a,Point b){return a.dis<b.dis;}struct node{      int l,r;      ll sum;}tree[N*4];  void pushup(int id){tree[id].sum = tree[R(id)].sum + tree[L(id)].sum;}void build(int l,int r,int id){tree[id].l = l, tree[id].r = r;tree[id].sum = r - l + 1;if(l == r)return ;int mid = Mid(l,r);build( l, mid, L(id));build( mid+1, r, R(id));}void updata(int l, int r,int id){if(l == tree[id].l && tree[id].r == r){ tree[id].sum = 0; return ;}int mid=Mid(tree[id].l, tree[id].r);if(r <= mid)updata(l, r, L(id));else if(mid < l) updata(l, r, R(id));else {updata(l, mid, L(id));updata(mid+1, r, R(id));}pushup(id);}int query(int l, int r, int id){if(tree[id].sum==0)return 0;if( tree[id].l == tree[id].r)return tree[id].sum;int mid=Mid(tree[id].l, tree[id].r);if(r <= mid)return query(l, r, L(id));if(mid < l )return query(l, r, R(id));return query(l, mid, L(id)) + query(mid+1, r, R(id));}int main(){int n, m, i,temp;while(~scanf("%d %d",&n,&m)){for(i=1;i<=m;i++){scanf("%d %d",&p[i].x,&p[i].y);if(p[i].x>p[i].y)temp=p[i].x, p[i].x=p[i].y, p[i].y=temp;p[i].dis=p[i].y-p[i].x;}sort(p+1, p+m+1, cmp);build(1,n,1);int ans=0;for(i=1;i<=m;i++){ans=Max(ans, query(p[i].x, p[i].y, 1));updata(p[i].x+1, p[i].y-1, 1);}ans=Max(ans, query(1,n,1));printf("%d\n",ans);}return 0;}/*6 31 51 41 3ans:3*/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.