DES:顺时针给出构成凸多边形的点。然后有Q个询问任意给出两个点的编号,询问由这两个点的连线将多边形分成的两部分面积较小的部分面积大小。

比赛时直接每次连线后求多边形求面积超时了。正确解法是求出利用叉积球三角形面积不断求和求出多边形总面积的同时,保留多边形的前缀和。当任意两点连线时,只要用前缀和想减再减去一个三角形的面积即可。

然而...我不理解的是关于q的那个循环...for就是超时...while就是AC...坐标明明是interger...int就WA...double就AC...

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
using namespace std; struct Point
{
double x, y;
} p[]; double areaa(Point p0, Point p1, Point p2) //计算以这三个点为顶点的三角形面积
{
double temp = (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
temp /= 2.0;
return fabs(temp);
} double area[]; // 存储多边形的前缀多边形的面积。 int main()
{
int n, q;
int xx, yy;
while(~scanf("%d%d", &n, &q))
{
for (int i=; i<n; ++i)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
}
double tot_area = ;
area[] = ;
area[] = ;
for (int i=; i<n-; ++i)
{
tot_area += areaa(p[], p[i], p[i+]);
area[i+] = tot_area;
}
int t1, t2;
double ans;
double temp_area; while(q--)
{
scanf("%d%d", &t1, &t2);
if (t2 > t1) swap(t1, t2); // 保证t1>t2
temp_area = area[t1]-area[t2]-areaa(p[], p[t1], p[t2]);
if (temp_area < tot_area-temp_area)
printf("%.1lf\n", temp_area);
else printf("%.1lf\n", tot_area-temp_area);
}
}
return ;
}

L哦哦K

SPOJ UMR 10A 计算几何的更多相关文章

  1. SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)

    Description You are given N circles and expected to calculate the area of the union of the circles ! ...

  2. SPOJ 149 FSHEEP Fencing in the Sheep ( 计算几何 + 二分 )

    以下摘自SPOJ泛做表格: 题意:给定一个星形多边形,而且给出了一个可以看到形内所有点的位置(我们称这个点为观察点),让你判断有多少个点位于多边形内. 时间复杂度:O(mlogn) 将多边形上的点按极 ...

  3. SPOJ CIRU The area of the union of circles (计算几何)

    题意:求 m 个圆的并的面积. 析:就是一个板子题,还有要注意圆的半径为0的情况. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...

  4. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  5. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  6. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  7. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  8. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

随机推荐

  1. UVa 1471 Defense Lines - 线段树 - 离散化

    题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...

  2. windows服务与自启动程序的区别(转载)

    转载:http://blog.csdn.net/anddy926/article/details/8464142 在客户端服务器项目实践中,作为服务端必须保持程序的24小时不间断运行,需要做一个监控, ...

  3. UNIX系统的显示时间何时会到尽头

    本文转载自:http://www.cnblogs.com/dfcao/p/expertCprogramming_intr0.html 本文分为三个小块: 一.UNIX系统中时间的存储形式: 二. ti ...

  4. assert函数用法总结【转】

    本文转载自:http://blog.csdn.net/u014082714/article/details/45190505 assert宏的原型定义在<assert.h>中,其作用是如果 ...

  5. boot sector FAT

  6. HDU 1711 Number Sequence(KMP模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 这道题就是一个KMP模板. #include<iostream> #include<cs ...

  7. UVa 1603 破坏正方形

    https://vjudge.net/problem/UVA-1603 题意:有一个火柴棍组成的正方形网格,计算至少要拿走多少根火柴才能破坏所有正方形. 思路:从边长为1的正方形开始遍历,将正方形的边 ...

  8. hdu 5651 xiaoxin juju needs help 逆元 两种求解方式

    xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  9. js 转义

    1. JavaScript 特殊字符 2. 正反斜杠互相替换 'a/b/c'.replace(/\//g,'\\')      //  "a\b\c" $0.value.repla ...

  10. springboot 解决 The bean 'userRepository', defined in null, could not be registered. A bean with that name has already been defined in file XXX and overriding is disabled.

    1.springboot 启动时报错: 2019-02-20 14:59:58.226 INFO 10092 --- [ main] c.f.s.SpringbootssmApplication : ...