zoj 3720
为什么注释掉的地方是错的? 自己的代码好糟烂.....
直接枚举点 判是否在多边形内 加起来求概率 求面积的时候代码写搓了....
比不过别人两行的代码 而且到现在还找不到错.....
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#define eps 1e-8
#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define offset 500
using namespace std;
const int N = 100;
struct point
{
double x, y;
point(double i, double j)
{
x = i, y = j;
}
point() {}
} p[N]; double xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int inside(point q, int n, point *p)
{
int s[3] = {1, 1, 1};
for(int i = 0; i < n && s[1]|s[2]; i++)
s[_sign(xmult(p[(i+1)%n], q, p[i]))] = 0;
return s[1]|s[2];
}
int inside_polygon(point q,int n,point* p)
{
point q2;
int i=0,count;
while (i<n)
for (count=i=0,q2.x=rand()+offset,q2.y=rand()+offset; i<n; i++)
{
if (zero(xmult(q,p[i],p[(i+1)%n]))&&(p[i].x-q.x)*(p[(i+1)%n].x-q.x)<eps
&&(p[i].y-q.y)*(p[(i+1)%n].y-q.y)<eps)
return 1;
else if (zero(xmult(q,q2,p[i])))
break;
else if (xmult(q,p[i],q2)*xmult(q,p[(i+1)%n],q2)<-eps&&
xmult(p[i],q,p[(i+1)%n])*xmult(p[i],q2,p[(i+1)%n])<-eps)
count++;
}
return count&1;
}
int main(void)
{
double x0,y0,xn,yn;
int a,b,n;
while(scanf("%lf%lf%lf%lf",&x0,&y0,&xn,&yn) == 4)
{
int _x0 = ceil(x0), _y0 = ceil(y0), _xn = floor(xn), _yn = floor(yn);
// printf("%d %d %d %d",_x0, _y0, _xn, _yn);
scanf("%d%d%d",&n,&a,&b);
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
double sum = 0;
for(int i = _x0; i <= _xn; i++)
for(int j = _y0; j <= _yn; j++)
{
if(inside_polygon(point(i, j), n, p))
{
double r=(min(i+0.5,xn)-max(i-0.5,x0))*(min(j+0.5,yn)-max(j-0.5,y0));
sum += r*(i*a+j*b);
// if(i > _x0 && i < _xn && j > _y0 && j < _yn)
// sum += (i*a+j*b);
// else if(i > _x0 && i < _xn && (j == _y0 || j == _yn))
// {
// if(j == _y0)
// sum += (i*a+j*b)*((double)((double)_y0-y0+0.5));
// else
// sum += (i*a+j*b)*((yn-(double)_yn+0.5));
// }
// else if((i == _x0 || i == _xn) && j > _y0 && j < _yn)
// {
// if(i == _x0)
// sum += (i*a+j*b)*(((double)_x0-x0+0.5));
// else
// sum += (i*a+j*b)*((xn-(double)_xn+0.5));
// }
// else
// {
// if(i == _x0 && j == _y0)
// sum += (i*a+j*b)*(((double)_x0-x0+0.5))*(((double)_y0-y0+0.5));
// else if(i == _x0 && j == _yn)
// sum += (i*a+j*b)*(((double)_x0-x0+0.5))*((yn-(double)_yn+0.5));
// else if(i == _xn && j == _y0)
// sum += (i*a+j*b)*((xn-(double)_xn+0.5))*(((double)_y0-y0+0.5));
// else
// sum += (i*a+j*b)*((xn-(double)_xn+0.5))*((yn-(double)_yn+0.5));
// }
}
}
printf("%.3lf\n",(double)sum/(xn-x0)/(yn-y0));
}
return 0;
}
zoj 3720的更多相关文章
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- ZOJ 1958. Friends
题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...
随机推荐
- Javascript之三种按钮点击事件
学习Javascript必须要先掌握基本的事件方法和语法,这些都是我们学过的也是最基本的.以前忘了总结,所以现在回顾,综合地总结一下,温故而知新. Javascript有三种按钮点击事件,分别为ale ...
- 【Android学习】尺寸单位 px in mm pt dp sp
一.Android中支持的尺寸单位 下面用表格的方式将Android中支持的尺寸单位列举,供大家参考: Android的尺寸单位 单位表示 单位名称 单位说明 px 像素 屏幕上的真实像素 ...
- Dreamweaver标签库
.highlight .hll { background-color: #ffffcc } .highlight { background: #ffffff } .highlight .c { col ...
- c# DataGridView操作
#region 操作DataGridView /// <summary> /// 初始化DataGridView属性 /// </summary> /// <param ...
- [译]使用Babel和Browserify创建你的ES6项目
原文地址:Setting up an ES6 Project Using Babel and Browserify JavaScript的发展日新月异,ES6很快就要接管JS了.很多著名的框架像Ang ...
- pgpool常用命令
启动pgpool pgpool -n -d > /tmp/pgpool.log >& & 停止pgpool pgpool stop pgbench的测试命令 pgbench ...
- dsu + lca
贴一下使用dsu和lca的代码,dsu的代码很简单,可以马上写出来,但是lca的代码就不熟练了.这里lca的计算还是用了dfs的访问时间标记,我想起来割边, 割点的判断, dfu[u], low[u] ...
- Z-Stack ZMain学习
[注:本文源自博客园http://www.cnblogs.com/cherishui/,为尊重劳动者成果,如需转载请保留此行] 在TI已有的Z-Stack的工程下面,打开已有的demo文件,通过分析不 ...
- oracle 之路目录
oracle linux单机安装 oracle windows单机安装创建实例卡死解决办法 oracle rac安装 HPDL380G8平台11.2.0.3 RAC实施手册 pl-sql develo ...
- CentOS 下安装JDK
前提条件 使用干净的centOS 之前肯定没有装过JDK 所以忽略卸载步骤 <1>从SUN下载jdk-1_5_0_14-linux-i586-rpm.bin或jdk-1_5_0_14-li ...