注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

凸包 hdu2907 && TZC 1786 Diamond Dealer  

2010-04-03 20:15:08|  分类: ACM |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Diamond Dealer

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


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.

凸包 hdu2907  TZC 1786   Diamond Dealer - 东月之神 - 东月之神


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
 
 
凸包问题,找到凸包的边数n2条, 求出凹的地方有ans个, 价值cnt = -p * ans + (n2-ans) * q;然后判断一下cnt > 0 ? cnt : 0;
因为点是顺时针给你的。所以先用个凸包求出那个边数。。然后再查找一下就可以了。。
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
struct Point
{
 double x, y;
 int num;
};
inline double cross(Point p1, Point p2, Point p3)
{
 return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
bool cmp(const Point &a, const Point &b)
{
 if(a.y < b.y) return true;
 if(a.y > b.y) return false;
 if(a.x < b.x) return true;
}
inline void getconvexhull(Point p1[], int n, Point p2[], int &top)
{
 sort(p1, p1+n, cmp);
 top = 0;
 int i;
 p2[top++] = p1[0];
 p2[top++] = p1[1];
 for(i = 2; i < n; i++)
 {
  while(top >= 2 && (cross(p2[top-2], p2[top-1], p1[i])) <= 0)
   --top;
  p2[top++] = p1[i];
 }
 int r = top;
 for(i = n - 2; i >= 0; i--)
 {
  while(top > r && (cross(p2[top-2], p2[top-1], p1[i])) <= 0)
   --top;
  if(i != 0)
   p2[top++] = p1[i];
 }
}
int main()
{
 int n, n2, i, j;
 int p, q, t;
 scanf("%d", &t);
 while(t--)
 {
  scanf("%d%d%d", &p, &q, &n);
  Point p1[31], p2[31];
  for(i = 0; i < n; i++)
  {
   scanf("%lf%lf", &p1[i].x, &p1[i].y);
   p1[i].num  = i;
  }  
  getconvexhull(p1, n, p2, n2);
  bool hash[31];
  memset(hash, false, sizeof(hash));
  for(i = 0; i < n2; i++)
   hash[p2[i].num] = true;
  hash[n] = hash[0];
  int ans = 0;
  for(i = 0; i < n; i++)
   if(hash[i] == 1 && hash[i+1] == 0)
    ans++; 
  int cnt = -p * ans + (n2 - ans) * q;
  printf("%d\n", cnt > 0 ? cnt : 0);
 }
return 0;
}
  评论这张
 
阅读(360)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017