日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

南邮 OJ 1408 火星探险

發(fā)布時間:2023/12/18 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 南邮 OJ 1408 火星探险 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

火星探險

時間限制(普通/Java)?:?1000 MS/?3000 MS?? ? ? ???運行內存限制 : 65536 KByte
總提交 : 62 ? ? ? ?? ? 測試通過 : 19?

比賽描述

在2051年,若干火星探險隊探索了這顆紅色行星的不同的區(qū)域并且制作了這些區(qū)域的地圖。現(xiàn)在, Baltic空間機構有一個雄心勃勃的計劃:他們想制作一張整個行星的地圖。為了考慮必要的工作,他們需要知道地圖上已經存在的全部區(qū)域的大小。你的任務是寫一個計算這個區(qū)域大小的程序。

任務:

l?????????從輸入讀取地圖形狀的描述

l?????????計算地圖覆蓋的全部的區(qū)域

l?????????輸出



輸入

輸入第一行包含一個整數(shù)N(1<=N<=10000),表示可得到的地圖數(shù)目。

以下N行,每行描述一張地圖。

每行包含4個整數(shù)x1,y1,x2和y2(0<=x1<x2<=30000,0<=y1<y2<=30 000)。數(shù)值(x1,y1)和(x2,y2)是坐標,分別表示繪制區(qū)域的左上角和右下角坐標。每張地圖是矩形的,并且它的邊是平行與X坐標軸或Y坐標軸的。

輸出

輸出應該包含一個整數(shù),表示探索區(qū)域的總面積(即所有矩形的公共面積)

樣例輸入

2
10?10?20?20
15?15?25?30

樣例輸出

225

提示

undefined

題目來源

JSOI2010



/* Time Limit Exceed at Test 2 #include<iostream> #include<algorithm> #include<set> using namespace std; #define MAX_N 10001struct line{int x1,x2,y;bool upIsArea; };bool operator<(const line &l1,const line &l2){if(l1.y!=l2.y){return l1.y<l2.y;}return l1.upIsArea; //同樣 y 的情況下,上面是面積的話,算小 }int main(){ // freopen("test.txt","r",stdin);int n,x1,y1,x2,y2;line l1;set<int> xs;set<int>::iterator it1,it2;multiset<line> ls;multiset<line>::iterator lIt;scanf("%d",&n);while(n--){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);xs.insert(x1);xs.insert(x2);l1.x1 = x1;l1.x2 = x2;l1.y = y1;l1.upIsArea = 1;ls.insert(l1);l1.y = y2;l1.upIsArea = 0;ls.insert(l1);}it1 = it2 = xs.begin();++it2;int deltaX,buttonY,count;int area=0;while(it2 != xs.end()){deltaX = *it2 - *it1;count = 0;buttonY = ls.begin()->y;for(lIt = ls.begin(); lIt!=ls.end(); ++lIt){if(lIt->x1 <= *it1 && lIt->x2 >= *it2){if(lIt->upIsArea){count++;if(count==1){buttonY = lIt->y;}}else{count--;if(count==0){area += deltaX * (lIt->y - buttonY);}}}}++it1;++it2;}printf("%d\n",area); } *//* 37MS Internet #include<stdio.h> #include<algorithm> #include<string.h> #include<iostream> using namespace std; const int MAXN=30001; struct Node {int l,r;int c;double lf,rf;double cnt;//覆蓋一次以上的長度double more;//覆蓋兩次以上的長度 }segTree[MAXN<<2]; struct Line {double x,y1,y2;double f; }line[MAXN];double y[MAXN];bool cmp(Line a,Line b) {return a.x<b.x; }void Build(int i,int l,int r) {segTree[i].l=l;segTree[i].r=r;segTree[i].cnt=0;segTree[i].more=0;segTree[i].lf=y[l];segTree[i].rf=y[r];if(l+1==r)return;int mid=(l+r)>>1;Build(i<<1,l,mid);Build((i<<1)|1,mid,r); } void calen(int i) {if(segTree[i].c>=2){segTree[i].more=segTree[i].cnt=segTree[i].rf-segTree[i].lf;return;}else if(segTree[i].c==1){segTree[i].cnt=segTree[i].rf-segTree[i].lf;if(segTree[i].l+1==segTree[i].r)segTree[i].more=0;else segTree[i].more=segTree[i<<1].cnt+segTree[(i<<1)|1].cnt;}else{if(segTree[i].l+1==segTree[i].r){segTree[i].cnt=segTree[i].more=0;}else{segTree[i].cnt=segTree[i<<1].cnt+segTree[(i<<1)|1].cnt;segTree[i].more=segTree[i<<1].more+segTree[(i<<1)|1].more;}} } void update(int i,Line e) {if(e.y1==segTree[i].lf&&segTree[i].rf==e.y2){segTree[i].c+=e.f;calen(i);return;}if(e.y2<=segTree[i<<1].rf) update(i<<1,e);else if(e.y1>=segTree[(i<<1)|1].lf) update((i<<1)|1,e);else{Line temp=e;temp.y2=segTree[i<<1].rf;update(i<<1,temp);temp=e;temp.y1=segTree[(i<<1)|1].lf;update((i<<1)|1,temp);}calen(i); } int main() {//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int n;double x1,y1,x2,y2;scanf("%d",&n);int t=1;for(int i=1;i<=n;i++){scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);line[t].x=x1;//這里題目描述有問題?左下角和右上角line[t].y1=y1;line[t].y2=y2;line[t].x=x1;line[t].f=1;y[t]=y1;t++;line[t].y1=y1;line[t].y2=y2;line[t].x=x2;line[t].f=-1;y[t]=y2;t++;}sort(line+1,line+t,cmp);sort(y+1,y+t);Build(1,1,t-1);update(1,line[1]);double ans=0;for(int i=2;i<t;i++){ans+=segTree[1].cnt*(line[i].x-line[i-1].x);update(1,line[i]);}printf("%.0lf\n",ans);return 0; } *//* 18MS #include<stdio.h> #include<algorithm> #include<string.h> #include<iostream> using namespace std; const int MAXN=30001; struct Node {int l,r;int c;int lf,rf;int cnt;//覆蓋一次以上的長度int more;//覆蓋兩次以上的長度 }segTree[MAXN<<2]; struct Line {int x,y1,y2;int f; }line[MAXN];int y[MAXN];bool cmp(Line a,Line b) {return a.x<b.x; }void Build(int i,int l,int r) {segTree[i].l=l;segTree[i].r=r;segTree[i].cnt=0;segTree[i].more=0;segTree[i].lf=y[l];segTree[i].rf=y[r];if(l+1==r)return;int mid=(l+r)>>1;Build(i<<1,l,mid);Build((i<<1)|1,mid,r); } void calen(int i) {if(segTree[i].c>=2){segTree[i].more=segTree[i].cnt=segTree[i].rf-segTree[i].lf;return;}else if(segTree[i].c==1){segTree[i].cnt=segTree[i].rf-segTree[i].lf;if(segTree[i].l+1==segTree[i].r)segTree[i].more=0;else segTree[i].more=segTree[i<<1].cnt+segTree[(i<<1)|1].cnt;}else{if(segTree[i].l+1==segTree[i].r){segTree[i].cnt=segTree[i].more=0;}else{segTree[i].cnt=segTree[i<<1].cnt+segTree[(i<<1)|1].cnt;segTree[i].more=segTree[i<<1].more+segTree[(i<<1)|1].more;}} } void update(int i,Line e) {if(e.y1==segTree[i].lf&&segTree[i].rf==e.y2){segTree[i].c+=e.f;calen(i);return; //子節(jié)點不需要更新?}if(e.y2<=segTree[i<<1].rf) update(i<<1,e);else if(e.y1>=segTree[(i<<1)|1].lf) update((i<<1)|1,e);else{Line temp=e;temp.y2=segTree[i<<1].rf;update(i<<1,temp);temp=e;temp.y1=segTree[(i<<1)|1].lf;update((i<<1)|1,temp);}calen(i); } int main() {freopen("test.txt","r",stdin);int n;int x1,y1,x2,y2;scanf("%d",&n);int t=1;for(int i=1;i<=n;i++){scanf("%d%d%d%d",&x1,&y1,&x2,&y2);line[t].x=x1;line[t].y1=y1;line[t].y2=y2;line[t].x=x1;line[t].f=1;y[t]=y1;t++;line[t].y1=y1;line[t].y2=y2;line[t].x=x2;line[t].f=-1;y[t]=y2;t++;}sort(line+1,line+t,cmp);sort(y+1,y+t);Build(1,1,t-1);update(1,line[1]);int ans=0;for(int i=2;i<t;i++){ans+=segTree[1].cnt*(line[i].x-line[i-1].x);update(1,line[i]);}printf("%d\n",ans);return 0; } */





總結

以上是生活随笔為你收集整理的南邮 OJ 1408 火星探险的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。