首页 > 其他分享 >POJ - 1765

POJ - 1765

时间:2024-09-03 19:38:29浏览次数:5  
标签:rt pp int double tree len POJ 1765

第一次做扫描线
挺好的

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct ppx {
	int l,r;
	double left,right;
	double len;
	int cover;//记录重边情况
} tree[4*200+10];
double y[200+10];//对应的序号装对应的边
struct pp {
	double x;
	double y1,y2;
	int flag;//标记入边还是出边
} node[200+10];
bool cmp(pp s,pp t) {
	return s.x<t.x;
}
void build(int rt,int left,int right) {
	tree[rt].l=left;
	tree[rt].r=right;
	tree[rt].left=y[left];
	tree[rt].right=y[right];
	tree[rt].len=0;
	tree[rt].cover=0;
	if(tree[rt].l+1==tree[rt].r) {
		return ;
	}
	int m=(left+right)/2;
	build(rt<<1,left,m);
	build((rt<<1)+1,m,right);
}
void solve(int rt) {
	if(tree[rt].cover>0) {
		tree[rt].len=tree[rt].right-tree[rt].left;//求这段区间长度
	} else if(tree[rt].r-tree[rt].l==1) { //长度清0
		tree[rt].len=0;
	} else {
		tree[rt].len=tree[rt<<1].len+tree[(rt<<1)+1].len;//长度递归到线段树的根
	}
}
void updata(int rt,pp b) { //写那么复杂为了节省时间
	if(b.y1==tree[rt].left&&b.y2==tree[rt].right) { //区间查找嘛。。。
		tree[rt].cover+=b.flag;
	} else if(b.y2<=tree[rt<<1].right) { //找左子树。。。
		updata(rt<<1,b);
	} else if(b.y1>=tree[(rt<<1)+1].left) { //找右子树。。。。
		updata((rt<<1)+1,b);
	} else { //分成两段。。。。左子树和右子树,。。。。
		pp temp;
		temp=b;
		temp.y2=tree[rt<<1].right;
		updata(rt<<1,temp);
		temp=b;
		temp.y1=tree[(rt<<1)+1].left;
		updata((rt<<1)+1,temp);
	}
	solve(rt);//区间的长度更新啦
}
int main() {
	int n,cases=1;
	while(~scanf("%d",&n)&&n) {
		int t=1;
		for(int i=1; i<=n; i++) {
			scanf("%lf%lf",&node[t].x,&y[t]);
			scanf("%lf%lf",&node[t+1].x,&y[t+1]);
			node[t].y1=y[t];
			node[t].y2=y[t+1];
			node[t+1].y1=y[t];
			node[t+1].y2=y[t+1];
			node[t].flag=1;
			node[t+1].flag=-1;
			t+=2;
		}
		sort(node+1,node+t,cmp);
		sort(y+1,y+t);
		build(1,1,t-1);//为啥t-1,因为现在t比序号大一了。。。因为上面的循环
		updata(1,node[1]);//先算第一条边。。。
		double sum=0;
		for(int i=2; i<t; i++) {
			sum+=tree[1].len*(node[i].x-node[i-1].x);//瞅见没,这就是求面积的。。// printf("%lf %lf\n",node[i].x-node[i-1].x,tree[1].len);
			updata(1,node[i]);
		}
		printf("Test case #%d\n",cases++);
		printf("Total explored area: %.2f\n\n",sum);
	}
}

标签:rt,pp,int,double,tree,len,POJ,1765
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18395264

相关文章

  • POJ - 1870
    先把蜂巢快递柜画出来:__________/\__/\__/\__/\____/\__/\__/53\__/\__/\__/\__/\__/52\__/54\__/\__/\\__/\__/51\__/31\__/55\__/\__//\__/50\__/30\__/32\__/56\__/\\__/49\__/29\__......
  • POJ - 3318
    他说:O(n^3)是过不了滴一搜……6代码和题解没有实质区别:#include<cstdio>#include<ctime>#include<cstdlib>usingnamespacestd;inta[505][505],b[505][505],c[505][505];intmain(){ srand(time(NULL)); intn; ios::sync_with_stdio(0); cin.tie(0); while(cin......
  • POJ - 2976
    原来是二分谁对平均分贡献大选谁界限<0.001,100次足矣#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>usingnamespacestd;constintmaxn=1010;intn,k;doublemid;structNode{ doublea,b;}w[maxn];boolcmp(Nodex,Nodey......
  • POJ - 3071
    概率题。本蒟蒻不会概率dp,于是手搓枚举。反正爆枚够用后记:SadBee的想法考虑维护每队对上上一队/下一队的胜率。只有两队最简单,用1乘即可那多队呢?不如看成两队。见:P(1胜)=P(1战胜2)P(3战胜4)P(1战胜3)+P(1战胜2)P(4战胜3)P(1战胜4)P(2胜)=......
  • POJ1321-棋盘问题
    POJ从23号崩了,放弃POJ(也不知是不是有比赛把oj都关了),各大OJLeetcode/PAT各种花里胡哨开会员能数据,它不配正经刷题牛客网招聘多课程广告多我焦虑不想入hdoj和洛谷不错,找了找搜索算法的题目单,之前看过数一巨巨写的知乎:邝斌带你飞专题,无限回忆西安艾教培训,卿俊888上交知乎咨询,科技......
  • TopoJSON格式详解,写入读取TopoJSON示例
    还是大剑师兰特:曾是美国某知名大学计算机专业研究生,现为航空航海领域高级前端工程师;CSDN知名博主,GIS领域优质创作者,深耕openlayers、leaflet、mapbox、cesium,canvas,webgl,echarts等技术开发,欢迎加底部微信(gis-dajianshi),一起交流。No.内容链接1Openlayers【入门教程】-......
  • D40 2-SAT POJ3683 Priest John's Busiest Day
    视频链接:D402-SATPOJ3683PriestJohn'sBusiestDay_哔哩哔哩_bilibili   POJ3683--PriestJohn'sBusiestDay(poj.org)#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>usingnamespacestd;......
  • SPOJ COT3 - Combat on a tree
    挺好的一个题,算是博弈和DS的有机结合这类问题一眼考虑SG函数,同时树上的SG函数一般都是从子树向上递推考虑若某个点的子树内全是黑点,则其SG函数为零;否则考虑枚举所有的后继状态不难发现选中一个白点会把这个子树断成一个森林,这个后继状态的SG函数就是每个连通块SG函......
  • flink stream转table POJO对象遇到的坑
    核心代码publicclassTrackLog{privateIntegerentityId;//flink的时间类型,必须使用LocalDateTimeprivateLocalDateTimestatDateTime; publicIntegergetEntityId(){returnentityId;}publicvoidsetEntityId(IntegerentityId){......
  • 【项目实战】解码软件工程:一文读懂DO/PO/BO/AO/DTO/DAO/POJO/VO的奥秘
    文章目录一文读懂DO/PO/BO/AO/DTO/DAO/POJO/VO的奥秘不同领域作用POJO(PlainOldJavaObject)VO(ValueObject)VO(ViewObject)的特点:实体类(Entity)数据传输对象(DTO)领域对象(DomainObject)持久化对象(PersistentObject)业务对象(BusinessObject)应用对象(ApplicationObject)......