hdu 1542(数学+yy)
来源:互联网 发布:网站域名分类几级 编辑:程序博客网 时间:2024/04/27 23:55
点击打开链接
题意:
给你n个矩形的顶点坐标,求着n个矩形的面积和
将矩形分为一块一块的,重点是要标记矩形内部的整点,最后求面积=sum(对应区域的面积*对应区域的标记值)
#include"stdio.h"#include"string.h"#include"algorithm"using namespace std;#define N 101int n;struct node{double x1,x2;double y1,y2;}A[N];int search(double *a,double x){int low,high,mid;low=0;high=2*n-1;while(low<=high){mid=(low+high)/2;if(a[mid]==x)return mid;else if(a[mid]<x)low=mid+1;else high=mid-1;}return 0;}int main(){int t;int i,j,k;int xy[2*N][2*N];double x[2*N],y[2*N];t=1;while(scanf("%d",&n)!=-1&&n){j=0;for(i=0;i<n;i++){scanf("%lf%lf%lf%lf",&A[i].x1,&A[i].y1,&A[i].x2,&A[i].y2);x[j]=A[i].x1;y[j]=A[i].y1;j++;x[j]=A[i].x2;y[j]=A[i].y2;j++;}sort(x,x+2*n);sort(y,y+2*n);memset(xy,0,sizeof(xy));int f1,f2,f3,f4;for(i=0;i<n;i++){f1=search(x,A[i].x1);f2=search(x,A[i].x2);f3=search(y,A[i].y1);f4=search(y,A[i].y2);for(j=f1;j<f2;j++){for(k=f3;k<f4;k++)xy[j][k]=1;}}double ans;ans=0;for(i=0;i<2*n;i++){for(j=0;j<2*n;j++)ans+=(x[i+1]-x[i])*(y[j+1]-y[j])*double(xy[i][j]);}printf("Test case #%d\n",t++);printf("Total explored area: %.2f\n",ans);printf("\n");}return 0;}
- hdu 1542(数学+yy)
- HDU 4611 数学+YY
- hdu 1722 Cake 数学yy
- HDU 4923 Room and Moor(数学+YY)(好题)
- HDU 4296 Buildings (YY)
- 数学-> YY POJ 1338
- 7_13_R题 yy math problem(数学、模拟)
- 2015 Multi-University Training Contest 3(hdu 5316、5317、5319、5323、5325、5326)线段树+数学+yy+矩阵快速幂
- !HDU 4145--思维(yy题)--(细节)
- hdu 3833 YY's new problem(hash表)
- hdu 3833 YY's new problem(哈希)
- HDU 3860 Naughty fairies ( C++ 代码 YY策略 + 高精度 )
- !HDU 4149 Magic Potion-yy-(二进制位运算技巧)
- HDU 5407 CRB and Candies(数论+yy)
- HDU 5514 Frogs(欧拉函数+数论YY)
- hdu 1061(数学)
- hdu 4153(数学)
- hdu 1403 (数学)
- 自定义控件添加事件
- 找学生妹
- XMPP 协议分析(四)
- Post和Get的区别(兼谈页面间传值的方式)
- 做一个懒COCOS2D-X程序猿(一)停止手打所有cpp文件到android.mk[转]
- hdu 1542(数学+yy)
- GridEX表格操作
- 关于redis、memcache、mongoDB 的对比
- 总结了编译Com技术内幕的最后例子的编译问题. 收藏
- SpriteKit学习笔记(六)关于SpriteKit与cocos2d
- 关于mysql函数GROUP_CONCAT的使用
- does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-l
- UVa400 Unix ls
- hdu 1028 Ignatius and the Princess III 母函数