zoukankan      html  css  js  c++  java
  • gym 101081 E. Polish Fortress 几何

    E. Polish Fortress
    time limit per test
    2.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    The Malbork castle is the largest brick castle in the world. It was built in 1274 in honor to Holy Mary, and is located near the river Nogat, in Poland. During World War II it was totally destroyed. In this times it was discovered that the castle was actually built in many phases, and it was surrounded by a fortress and a wall centuries after it had began building.

    In those times wall building was a very elaborate task. War tactics showed that it was convenient to build niches in the walls, that is, a recess on them. In these niches a soldier could stand in relative safety, since he could see all the area determined by the line segments in the niche without needing to turn his head (it was considered they field of vision of 180 degrees). The more niches a wall had, the safer the fortress was considered.

    Your task in this problem is, given N points, the corners of the fortress, determine how many of them are niches as described above, in which soldiers could stand to protect the castle.

    Input

    The first line has an integer N, the number of corners of the fortress. Each of the next N lines has two integers Xi and Yi, the coordinates of a fortress corner. The corners are given in clockwise or counterclockwise order. There are no three consecutive colinear points and the wall does not intersect itself.

    Limits

    • 3 ≤ N ≤ 105
    • |X|, |Y| ≤ 1.8·104
    Output

    Print a single integer, the number of niches in the fortress.

    Examples
    input
    13
    0 0
    700 100
    400 500
    1300 600
    700 400
    1400 200
    2200 1200
    1500 2000
    1500 1700
    400 1700
    400 2200
    0 1900
    10 1000
    output
    5
    input
    3
    -32 45
    2 19
    -100 -3
    output
    0
    Note

    The image shows the first example.

    思路:判断多边形是否为逆时针输入(计算多边形面积),找有向面积小于0的连续三角形数目;

       否则相反;

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<bitset>
    #include<set>
    #include<map>
    #include<time.h>
    using namespace std;
    #define LL long long
    #define pi (4*atan(1.0))
    #define eps 1e-8
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=2e5+10,M=1e6+10,inf=1e9+10;
    const LL INF=1e18+10,mod=1e9+7;
    
    struct Point
    {
        double x, y ;
    } p[N];
    int n ;
    double Area( Point p0, Point p1, Point p2 )// 求三角形面积公式//叉积
    {
        double area = 0 ;
        area =  (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
        return area / 2 ;  
    }
    int ans1,ans2;
    double xjhz1()
    {
        double sum_area = 0 ;
        for ( int i = 2 ; i < n ;  i++ )
        {
            double area = Area(p[0],p[i-1],p[i]) ;
            sum_area += area ;
        }
        return sum_area;
    }
    void gans()
    {
        for (int i = 2 ; i-1<= n ;  i++ )
        {
            double temp = Area(p[i-2],p[i-1],p[i]) ;
            if(temp<0.0)ans1++;
            else ans2++;
        }
    }
    int main ()
    {
        scanf ( "%d", &n );
        for(int i=0; i<n; i++)
            scanf ( "%lf%lf", &p[i].x, &p[i].y ),p[i+n]=p[i];
        double sum=xjhz1();
        gans();
        if(sum>0)printf("%d
    ",ans1);
        else printf("%d
    ",ans2);
        return 0 ;
    }
  • 相关阅读:
    CEO良言:创业就请在29岁前做富翁
    在酒桌上看出她是哪种女人!
    巴菲特的人生财富课
    曹操的领导力:羊群变狮群(领导艺术终极体现)
    商业模式木桶短板原理与长板原理
    这三种力量,让你的人生从此大不一样……
    都市男女的30句妙语叹息
    郎咸平:诸葛亮是一名优秀的企业家吗?
    做小生意,解决生活中的问题:创业路上的成功感悟
    100个成功经验(价格不菲的培训课程笔记摘要)
  • 原文地址:https://www.cnblogs.com/jhz033/p/7514829.html
Copyright © 2011-2022 走看看