POJ1151(求矩阵的并面积) 离散化
来源:互联网 发布:最新抢火车票软件 编辑:程序博客网 时间:2024/06/06 03:10
find函数直接用了线性搜索,居然没有TLE。
#include <iostream>#include <algorithm>#include <map>#include <cstdio>using namespace std;struct rec{double x1;double y1;double x2;double y2;};int find(double aim,double* arr,int T){int i;for (i=0;i<=T-1;i++){if (aim==arr[i]) return i;}}int main(){ int T;int num=0;while (1){num++;int i;int j;int k;double ans=0;int posx1;int posx2;int posy1;int posy2;int counterx=0;int countery=0;int total=0;int cover[200][200]={{0}};double x[200];double y[200];rec rectangle[100];map<double,bool> rx,ry;map<double,bool>::iterator iter;cin >> T;if (num!=1 && T!=0)cout << endl << endl;if (T==0)break;for (i=0;i<=T-1;i++){cin >> rectangle[i].x1 >> rectangle[i].y1;cin >> rectangle[i].x2 >> rectangle[i].y2;//重复的坐标不应该添加进数组//true表示已存在,flase表示不存在iter=rx.find(rectangle[i].x1);if (iter==rx.end() || iter->second==false){ x[counterx]=rectangle[i].x1;rx[rectangle[i].x1]=true;counterx++;}iter=ry.find(rectangle[i].y1);if (iter==ry.end() || iter->second==false){ y[countery]=rectangle[i].y1;ry[rectangle[i].y1]=true;countery++;}iter=rx.find(rectangle[i].x2);if (iter==rx.end() || iter->second==false){ x[counterx]=rectangle[i].x2;rx[rectangle[i].x2]=true;counterx++;}iter=ry.find(rectangle[i].y2);if (iter==ry.end() || iter->second==false){ y[countery]=rectangle[i].y2;ry[rectangle[i].y2]=true;countery++;}}sort(x,x+counterx);sort(y,y+countery);for (i=0;i<=T-1;i++){//对于每个矩阵找到坐标在数组中的位置 posx1=find(rectangle[i].x1,x,counterx);posx2=find(rectangle[i].x2,x,counterx);posy1=find(rectangle[i].y1,y,countery);posy2=find(rectangle[i].y2,y,countery);for (j=posx1;j<posx2;j++)for (k=posy1;k<posy2;k++){//第j行第k列的矩阵,1表示已覆盖cover[j][k]=1;}}for (i=0;i<=counterx-1;i++)for (j=0;j<=countery-1;j++){ if (cover[i][j]==1){ans+=(x[i+1]-x[i])*(y[j+1]-y[j]);}}cout << "Test case #" << num << endl;cout << "Total explored area: ";printf("%.2f",ans);}return 0;}
- POJ1151(求矩阵的并面积) 离散化
- POJ1151 离散化求矩形面积的并
- Poj1151/HDU1542(求并矩形覆盖的面积)分别用离散化处理,矩形切割,线段树三种方法实现.
- POJ1151-(线段树扫描线+离散化)求矩形面积并
- poj1151 Atlantis(线段树+扫描线+离散化,求矩形面积并)
- poj1151平面矩形面积并,双离散化
- Poj1151线段树求面积并
- POJ 1151 && 1389 离散化求矩形面积的并
- POJ1151 (HDU 1542) Atlantis【矩形面积并,线段树+离散化+扫描线模板】
- POJ1151 Atlantis(线段树,扫描线,离散化,矩形面积并)
- 离散化矩形面积求并
- 【坐标离散化】矩形面积求并
- POJ1151基本的扫描线求面积
- poj1151矩形面积并
- POJ1151矩形面积并
- hdu1255 覆盖的面积(线段树+扫描线+离散化,求矩形面积并)
- 【codevs3044】矩形面积求并&&【POJ1151】Atlantis,第一次的扫描线
- poj1151 hdu1542 wikioi3044 Atlantis 矩形面积求并
- 开源中国三个平台客户端均已全面开源
- Function.prototype.call.apply结合用法
- Linux下SVN客户端的使用方法
- Leetcode: Binary Tree Zigzag Level Order Traversal
- 心情历练 技术沉淀 生活积淀
- POJ1151(求矩阵的并面积) 离散化
- Struts2.x中获取request,response,session的方式
- Poj 1556 The Doors
- C# 读取Excel文件
- ffmepg 指定网络连接模式UDP还是TCP
- struts2的拦截器(3):通过实现Interceptor接口定义自己的拦截器
- 分布式数据库 HBase
- 开始写点东西
- VLC搭建RTSP服务器的过程