hdu 2907 Diamond Dealer(凸包)

Diamond Dealer

                                                                     Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                                                  Total Submission(s): 651    Accepted Submission(s): 190


Problem Description
Mr. Chou is the atworld diamond dealer. It is important that he knows the value of his (twodimensional) diamonds in order to be a succesful businessman. Mr. Chou is tired of calculating the values by hand and you have to write a program that makes the calculation for him.



Figure 2: Example diamond 

The value of a diamond is determined by smoothness of its surface. This
depends on the amount of faces on the surface, more faces means a smoother surface. If there are dents (marked red in gure 2) in the surface of the diamond, the value of the diamond decreases. Counting the number of dents in the surface (a) and the number of faces on the surface that are not in dents (b), the value of the diamond is determined by the following formula: v = -a * p + b * q. When v is negative, the diamond has no value (ie. zero value).
 

Input
The first line of input consists of the integer number n, the number of test cases;
Then, for each test case:
One line containing:
The cost for a dent in the surface of a diamond (0 <= p <= 100); 
The value of a face in the surface of a diamond (0 <= q <= 100); 
The number of vertices (3 <= n <= 30) used to describe the shape of the diamond.
n lines containing one pair of integers (-1000 <=xi,yi <= 1000) describing the surface of the diamond (x0,y0) - (x1,y1) -.....-(xn-1, yn-1) - (x0 ,y0) in clockwise order.
No combination of three vertices within one diamond will be linearly aligned.
 

Output
For each test case, the output contains one line with one number: the value of the diamond.
 

Sample Input
  
  
1 10 5 7 0 10 8 4 10 -7 6 -9 -5 -4 -5 7 -2 6
 

Sample Output
  
  
15
 

第一道凸包题,这题题意难懂些,就是求凸面和凹面,凸面价值为q,凹面价值为-p,求最后的总价值。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct node
{
    int x;
    int y;
    int id;
}point[110],stacks[110];
int top;
int hash[110];
int cross(node a,node b,node c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
double dis(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0);
}
bool cmp(node a,node b)
{
    int m=cross(point[0],a,b);
    if(m==0)
        return dis(point[0],a)<dis(point[0],b)?true:false;
    if(m>0)
        return true;
    else
        return false;
}
void graham_scan(int n)
{
    for(int i=1;i<n;i++)
    {
        if(point[i].y<point[0].y||(point[i].y==point[0].y&&point[i].x<point[0].x))
        {
            node temp;
            temp=point[0];
            point[0]=point[i];
            point[i]=temp;
        }
    }
        sort(point+1,point+n,cmp);
        memset(stacks,0,sizeof(stacks));
        stacks[0]=point[0];
        stacks[1]=point[1];
        top=2;
        for(int i=2;i<n;i++)
        {
            while(top>=2&&cross(stacks[top-2],stacks[top-1],point[i])<0)
            {
            top--;
            }
            stacks[top++]=point[i];
        }
}
int main()
{
    int p,q,n,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&p,&q,&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&point[i].x,&point[i].y);
            point[i].id=i;
        }
        graham_scan(n);//凸包
        int cou=0;
        memset(hash,0,sizeof(hash));
        for(int i=0;i<top;i++)
        {
            hash[stacks[i].id]=1;
        }
        hash[n]=hash[0];
        for(int i=0;i<n;i++)//凹面
        {
            if(hash[i]==1&&hash[i+1]==0)
            {
                cou++;
            }
        }

        int ans=top*q-cou*p-cou*q;
        if(ans>0)
        printf("%d\n",ans);
        else
        printf("0\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【1】项目代码完整且功能都验证ok,确保稳定可靠运行后才上传。欢迎下载使用!在使用过程中,如有问题或建议,请及时私信沟通,帮助解答。 【2】项目主要针对各个计算机相关专业,包括计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师或企业员工使用。 【3】项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 【4】如果基础还行,或热爱钻研,可基于此项目进行二次开发,DIY其他不同功能,欢迎交流学习。 【注意】 项目下载解压后,项目名字和项目路径不要用中文,否则可能会出现解析不了的错误,建议解压重命名为英文名字后再运行!有问题私信沟通,祝顺利! 基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值