zoukankan      html  css  js  c++  java
  • BZOJ1132: [POI2008]Tro

    1132: [POI2008]Tro

    Time Limit: 20 Sec  Memory Limit: 162 MB
    Submit: 815  Solved: 211
    [Submit][Status]

    Description

    平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000

    Input

    第一行给出数字N,N在[3,3000] 下面N行给出N个点的坐标,其值在[0,10000]

    Output

    保留一位小数,误差不超过0.1

    Sample Input

    5
    0 0
    1 2
    0 2
    1 0
    1 1

    Sample Output

    7.0

    HINT

    Source

    题解:

    这题我们每次以最左边的点为原点,将其它点按照极角排序(极角我想就是某点与原点连线的斜率),

    然后按标号枚举另一个点,利用叉积求面积,并且用部分和来优化。

    实数果然有精度问题。。记得/的时候要把数据强制转化为你需要的类型,否则做的就是整型除法。

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #define inf 1000000000
    13 #define maxn 3000+500
    14 #define maxm 500+100
    15 #define eps 1e-10
    16 #define ll long long
    17 #define pa pair<int,int>
    18 #define for0(i,n) for(int i=0;i<=(n);i++)
    19 #define for1(i,n) for(int i=1;i<=(n);i++)
    20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    22 using namespace std;
    23 inline int read()
    24 {
    25     int x=0,f=1;char ch=getchar();
    26     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    27     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    28     return x*f;
    29 }
    30 int n;
    31 struct rec{ll x,y;double z;}a[maxn];
    32 inline double kk(rec a,rec b)
    33 {
    34     if(b.x==a.x)
    35     {
    36         if(b.y<a.y)return -inf;else return inf;
    37     }
    38     return (double)(b.y-a.y)/(double)(b.x-a.x);
    39 }
    40 inline bool cmp(rec a,rec b)
    41 {
    42     return a.z<b.z;
    43 }
    44 int main()
    45 {
    46     freopen("input.txt","r",stdin);
    47     freopen("output.txt","w",stdout);
    48     n=read();
    49     for1(i,n)a[i].x=read(),a[i].y=read();
    50     ll ans=0;
    51     for1(i,n-2)
    52     {
    53       int k=i;    
    54       for2(j,i+1,n)if(a[j].x<a[k].x)k=j;
    55       swap(a[k],a[i]);
    56       for2(j,i+1,n)a[j].z=kk(a[i],a[j]);
    57       sort(a+i+1,a+n+1,cmp);    
    58       ll xx=0,yy=0;
    59       for2(j,i+1,n)
    60         {
    61           ans+=(a[j].x-a[i].x)*yy-(a[j].y-a[i].y)*xx;
    62           xx+=a[j].x-a[i].x;yy+=a[j].y-a[i].y;
    63               //cout<<ans<<' '<<xx<<' '<<yy<<' '<<a[j].x<<' '<<a[j].y<<' '<<a[j].z<<endl;
    64         }              
    65     }    
    66     printf("%lld",abs(ans)/2);
    67     if(ans&1)puts(".5");else puts(".0");
    68     return 0;
    69 }
    View Code
  • 相关阅读:
    调整swt table的行高
    获取TableViewer里面的所有TableViewerColumn
    jface viewer 全选
    jaxb生成pojo类返回类型为布尔值的问题
    EMF中复制对象属性
    向导中的参数传递 wizard param
    GEF中TreeViewer的叶子节点展开
    Cannot modify resource set without a write transaction 问题
    注册emf package并读取EMF文件
    从运行时的工作空间获取EMF文件(IFILE)
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3968857.html
Copyright © 2011-2022 走看看