zoukankan      html  css  js  c++  java
  • poj3348 Cows

    Cows
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 10039   Accepted: 4408

    Description

    Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

    However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

    Input

    The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

    Output

    You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

    Sample Input

    4
    0 0
    0 101
    75 0
    75 101

    Sample Output

    151

    Source

    大致题意:n个点,用一个绳子圈出尽可能大的面积,养一头牛要50的面,最多能养多少头?
    分析:凸包模板题.几个要点:1.找极点,将序号设为1. 2.根据极角和极点的距离排序. 3.维护一个最少有2个点的栈,再来考虑每个点能不能加进来,加进来会将多少个点从栈中删除,利用叉积判断.  4.利用叉积求面积.
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    int n,tot,ans;
    
    struct node
    {
        int x,y;
    }p[10010],q[10010];
    
    node sub(node a,node b)
    {
        node temp;
        temp.x = a.x - b.x;
        temp.y = a.y - b.y;
        return temp;
    }
    
    int det(node a,node b)
    {
        return a.x * b.y - a.y * b.x;
    }
    
    int dist(node a)
    {
        return (a.x - p[1].x) * (a.x - p[1].x) + (a.y - p[1].y) * (a.y - p[1].y);
    }
    
    bool cmp(node a,node b)
    {
        int temp = det(sub(a,p[1]),sub(b,p[1]));
        if (temp != 0)
            return temp > 0;
        return dist(a) < dist(b);
    }
    
    void Graham()
    {
        int id = 1;
        for (int i = 2; i <= n; i++)
        {
            if (p[i].x < p[id].x || (p[i].x == p[id].x && p[i].y < p[id].y))
                id = i;
        }
        if (id != 1)
            swap(p[1],p[id]);
        sort(p + 2,p + 1 + n,cmp);
        q[++tot] = p[1];
        for (int i = 2; i <= n; i++)
        {
            while (tot >= 2 && det(sub(p[i],q[tot - 1]),sub(q[tot],q[tot - 1])) >= 0)
                tot--;
            q[++tot] = p[i];
        }
    }
    
    int solve()
    {
        int res = 0;
        q[tot + 1] = q[1];
        for (int i = 1; i <= tot; i++)
            res += det(q[i],q[i + 1]);
        return res / 2;
    }
    
    int main()
    {
        scanf("%d",&n);
        for (int i = 1; i <= n; i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        Graham();
        ans = solve();
        printf("%d
    ",ans / 50);
    
        return 0;
    }
  • 相关阅读:
    使用jquery插件validate制作的表单验证案例
    POJ2992:Divisors(求N!因子的个数,乘性函数,分解n!的质因子(算是找规律))
    HDU1695:GCD(容斥原理+欧拉函数+质因数分解)好题
    HDU4135Co-prime(容斥原理)
    HDU1796How many integers can you find(容斥原理)
    Miller-Rabin素数测试算法(POJ1811Prime Test)
    乘法逆元+模的运算规则
    因子和与因子个数 (乘性函数)
    费马小定理的证明:
    整数(质因子)分解(Pollard rho大整数分解)
  • 原文地址:https://www.cnblogs.com/zbtrs/p/8111436.html
Copyright © 2011-2022 走看看