【poj3348】 Cows

http://poj.org/problem?id=3348 (题目链接)

题意:给出平面上n个点,以这n个点中的一些围成的多边形面积 div 50的最大值。

Solution 
  凸包求面积。 
  很好做,构造完凸包后从栈底开始向上求叉乘之和,也就是将凸包分成许多小三角形求面积和。

代码:

// poj3348
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<map>
#define inf 2147483640
#define LL long long
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
    LL x=0,f=1;char ch=getchar();
    while (ch>‘9‘ || ch<‘0‘) {if (ch==‘-‘) f=-1;ch=getchar();}
    while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}

const int maxn=10010;
struct point {int x,y;}p[maxn];
int s[maxn],n,top;

int cross(point p0,point a,point b) {
    return (a.x-p0.x)*(b.y-p0.y)-(a.y-p0.y)*(b.x-p0.x);
}
double dis(point a,point b) {
    return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(point a,point b) {
    int t=cross(p[1],a,b);
    if (t>0) return 1;
    else if (t==1 && dis(a,p[1])<dis(b,p[1])) return 1;
    else return 0;
}
void Graham() {
    if (n==1) s[top=1]=1;
    else if (n==2) {s[top=1]=1;s[++top]=2;}
    else {
        s[top=1]=1;s[++top]=2;
        for (int i=3;i<=n;i++) {
            while (top>1 && cross(p[s[top-1]],p[s[top]],p[i])<=0) top--;
            s[++top]=i;
        }
    }
}
double Size() {
    point p0=p[s[1]];
    double sum=0;
    for (int i=3;i<=top;i++) sum+=cross(p0,p[s[i-1]],p[s[i]]);
    return sum/2;
}
int main() {
    while (scanf("%d",&n)!=EOF) {
        int k=1;
        for (int i=1;i<=n;i++) {
            scanf("%d%d",&p[i].x,&p[i].y);
            if (p[i].x<p[k].x || (p[i].x==p[k].x && p[i].y<p[k].y)) k=i;
        }
        point p0=p[k];
        p[k]=p[1];p[1]=p0;
        sort(p+2,p+1+n,cmp);
        Graham();
        printf("%d\n",(int)Size()/50);
    }
    return 0;
}

  

时间: 2024-12-14 10:32:38

【poj3348】 Cows的相关文章

【POJ3621】Sightseeing Cows 分数规划

[POJ3621]Sightseeing Cows 题意:在给定的一个图上寻找一个环路,使得总欢乐值(经过的点权值之和)/ 总时间(经过的边权值之和)最大. 题解:显然是分数规划,二分答案ans,将每条边的权值变成(ans*边权-2*起始点点权),然后我们希望找出一个环,使得环上的总边权<0 (一开始我把题意理解错了,题中给的是单向边,我把它当成是双向边+每条边只能走一次了~,想出一堆做法都接连pass掉) 然后就直接用SPFA判负环就好了嘛!由于原图不一定联通,所以一开始就把所有点都入队就完事

poj 2186 Popular Cows 【强连通】

题目:poj 2186 Popular Cows 题意:n头牛,其中存在一些牛相互崇拜,具有传递性,问有多少头牛是被其他所有牛崇拜的. 分析:建立一个有向图,然后强连通缩点,之后求出度为0的点,假如存在多个,那么ans = 0,因为缩点之后如果x崇拜y,x也崇拜z,那么肯定y和z不能互相崇拜,不满足. 然后求出度为0的这个点缩点前环上有多少个点就ans AC代码: #include <cstdio> #include <vector> #include <iostream&g

【dfs】BZOJ1703-[Usaco2007 Mar]Ranking the Cows 奶牛排名

[题目大意] 农夫约翰有N(1≤N≤1000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率.约翰想要让这些奶牛按产奶率从高到低排序,约翰已经比较了M(1≤M≤10000)对奶牛的产奶率,但他发现,他还需要再做一张关于另外C对奶牛的产奶率比较,才能推断出所有奶牛的产奶率排序.请帮他确定C的最小值. [思路] 对于M对关系,从产奶率高的往产奶率低的连一条有向边.对于每个节点i,它能抵达的节点的总数即是能比较得出的比它小的奶牛总数. 由于原本总共有N*(N-1)/2对关系,ans=N*(N-

【BZOJ】1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名

[题意]给定n头牛和m对大小关系,求最坏情况下至少还需要比较几对奶牛的大小(在未确定顺序的奶牛对中随机比较) [算法]floyd求传递闭包 [题解]可达说明大小已知,则不可达点对数量就是最少比较次数. 使用bitset优化传递闭包,复杂度O(n^3 /32). #include<cstdio> #include<bitset> #include<algorithm> using namespace std; const int maxn=1010; int n,m; b

【POJ3169 】Layout (认真的做差分约束)

Layout Description Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <= 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows are standing in the same order as they ar

POJ No.3617【B008】

[B007]Best Cow Line[难度B]———————————————————————————————————————————————— [Description    支持原版从我做起!!!] FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year" competition. In this contest every farmer arranges his cows in

【POJ2185】【KMP + HASH】Milking Grid

Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently wri

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

【BZOJ3011】[Usaco2012 Dec]Running Away From the Barn 可并堆

[BZOJ3011][Usaco2012 Dec]Running Away From the Barn Description It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <=