HDU 3952(计算几何)

问题描述:

Fruit Ninja is a popular classic game. During the game, fruits will up to the air, and your aim is cut as more fruits as possible with a line. 







Even if the line touch a point of a fruit, the fruit also be cut.

Input

The first line is a number T(1<=T<=30), represents the number of case. The next T blocks follow each indicates a case. 
The first line of each case contains one integer N (1<=N<=10) 
Then N lines follow, each line contains a integer K(3<=K<=10), represent the number points of the fruit, then K*2 integers follow, each two integers represent one point of the fruit.(with anticlockwise order) 
I promise all fruits are convex polygon, and any two fruit have no common point.

Output

For each case, output the number of case and the maximum fruits you could cut with a line.(as shown in the sample output)

Sample Input

2
3
3 0 0 1 0 1 1
3 1 2 2 1 2 2
3 3 1 3 0 4 0
3
4 0 0 1 0 1 1 0 1
4 2 0 3 0 3 1 2 1
4 0 99 1 99 1 100 0 100
Sample Output

Case 1: 3
Case 2: 2
题目题意:题目给我们n个图形,每个图形给我们k个点(保证图形是凸图形),问一条直线最多可以经过多少个图形。

题目分析:我们假象一下,我们有一条直线现在经过了M个图形,那么当我们平移导致经过M-1个图形时,肯定会经过一个图形的某一顶点,那么经过M个图形的临界情况就是经过某俩个图形的顶点,然后再经过其他图形。我们枚举这个俩个点,这就是那条直线,然后去判断其他图形是否被这条直线穿过。


代码如下:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;

struct note
{
    int x,y;
};
int n;
vector<struct note> vec[20];

int cross(note a,note n,note m)//叉乘判断点a在直线nm的上方还是下方
{
    return (a.x-n.x)*(m.y-n.y)-(a.y-n.y)*(m.x-n.x);
}
bool check(note a,note b,note n,note m)
{
    return cross(a,n,m)*cross(b,n,m)<=0;//如果积为负则必有上下俩点,为0则有点在线上
}
int solve(struct note a,struct note b,int mm,int nn)
{
    int ans=2;//本身就经过俩个图形所以开始为2
    for (int i=0;i<n;i++) {
        if (i==mm||i==nn) continue;
        vector <struct note> s;
        s=vec[i];
        s.push_back(vec[i][0]);
        for (int j=0;j<s.size()-1;j++) {
            if (check(s[j],s[j+1],a,b)) {//去判断是否经过其他图形,枚举它的线段是否与直线相交
                ans++;
                break;
            }
        }
    }
    return ans;
}
int main()
{
    int t,icase=1;
    scanf("%d",&t);
    while (t--) {
        scanf("%d",&n);
        for (int i=0;i<n;i++) {
            int k;
            scanf("%d",&k);
            for (int j=0;j<k;j++) {
                struct note a;
                scanf("%d%d",&a.x,&a.y);
                vec[i].push_back(a);
            }
        }
        if (n==1) {//n=1是特判一下
            printf("Case %d: %d\n",icase++,1);
            continue;
        }
        int ans=0;
        for (int i=0;i<n-1;i++) {//枚举任意俩个图形的所有的顶点
            for (int j=0;j<vec[i].size();j++) {
                for (int k=i+1;k<n;k++) {
                    for (int l=0;l<vec[k].size();l++) {
                        int res=solve(vec[i][j],vec[k][l],i,k);
                        ans=max(ans,res);
                    }
                }
            }
        }
        for (int i=0;i<n;i++) vec[i].clear();
        printf("Case %d: %d\n",icase++,ans);
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值