poj 3348 Cows(볼륨 + 포크 면적)

[제목 대의]: 다각형을 주고 볼록 면적을 구하고 답안/50 정돈 출력을 구한다.
【문제풀이 사고방식】: 물문제, 볼록모형판+차적구 다각형면적
【코드】:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
                   
using namespace std;
                   
#define eps 1e-8
#define pi acos(-1.0)
#define inf 1<<30
#define linf 1LL<<60
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long

#define INF 999999999.9

struct Point{
    double x, y, dis;
}pt[10005],stack[10005],p0;//stack      
int top,tot;
int n;
double l;

//      
double get_dis(double x1, double y1, double x2, double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

//    ,   -1: p0p1 p0p2   ,  0:p0,p1,p2  
int Cmp_PolarAngel(struct Point p1, struct Point p2, struct Point pb){
    double delta=(p1.x-pb.x)*(p2.y-pb.y)-(p2.x-pb.x)*(p1.y-pb.y);
    if (delta<0.0) return 1;
    else if (delta==0.0) return 0;
    else return -1;
}

//     p2p3   p1p2    
bool Is_LeftTurn(struct Point p3, struct Point p2, struct Point p1){
    int type=Cmp_PolarAngel(p3, p1, p2);
    if (type<0) return true;
    return false;
}

//     ,         
int Cmp(const void*p1, const void*p2){
    struct Point*a1=(struct Point*)p1;
    struct Point*a2=(struct Point*)p2;
    int type=Cmp_PolarAngel(*a1, *a2, p0);
    if (type<0) return -1;
    else if (type==0){
        if (a1->disdis) return -1;
        else if (a1->dis==a2->dis) return 0;
        else return 1;
    }
    else return 1;
}

void get_area(int n,Point p[]){
    double area=0.0;
    p[n+1]=p[0];
    for (int i=0; i<=n; i++){
        area+=p[i].x*p[i+1].y-p[i+1].x*p[i].y;
    }
    area=fabs(area/2.0);
    printf("%.0f
",floor(area/50)); } // void Solve(int n){ int k; p0.x=p0.y=INF; for (int i=0; i=1 && Is_LeftTurn(pt[i],stack[top],stack[top-1])==false) top--; stack[++top]=pt[i]; } get_area(top,stack); } int main(){ while (~scanf("%d",&n)){ Solve(n); } return 0; }

좋은 웹페이지 즐겨찾기