HDU3952 Fruit Ninja (geometry)

Source: Internet
Author: User

The problem is asking you to ask for a line that can pass through the most fruit (a point is counted).

It can be proved that it is possible to enumerate the lines consisting of two points.

Because if there is a line that crosses n fruits, it is necessary to translate some of it so that it passes through n but it can no longer be translated, so the line must be at some end of a certain fruit.

Again with this end, rotate this line, or through N, until it cannot be rotated (then the rotation may not pass through N), so that the line must have encountered another endpoint.

So just enumerate two endpoints.

There is only one fruit, and a special sentence.

#include <map> #include <set> #include <queue> #include <stack> #include <math.h> #include <time.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h># include<string.h> #include <string> #include <algorithm> #define MID (x, y) >> 1 #define L ( x) (x << 1) #define R (x) (x << 1 | 1) using namespace Std;const int MAX = 35;struct point {int x, y;}; struct Polygon {point P[max]; int n,};p olygon g[max];int crossproduct (Point a,point b,point c) {return (c.x-a.x) * (b.y -A.Y)-(b.x-a.x) * (C.Y-A.Y);} BOOL S21_inst (Point s1,point s2,point l1,point L2) {return crossproduct (L1,L2,S1) *crossproduct (L1,L2,S2) <= 0;}    int solve (point a,point b,int n) {int ans=0;        for (int i=0;i<n;i++) {int LEN=G[I].N;        G[i].p[len] = g[i].p[0];                for (int k=0;k<len;k++) if (S21_inst (g[i].p[k],g[i].p[k+1],a,b)) {ans++;   Break         }} return ans;    int main () {int ncases,n;    int ind=1;    scanf ("%d", &ncases);        while (ncases--) {scanf ("%d", &n);            for (int i=0;i<n;i++) {scanf ("%d", &AMP;G[I].N);        for (int k=0;k<g[i].n;k++) scanf ("%d%d", &g[i].p[k].x,&g[i].p[k].y);            } if (n==1) {printf ("Case%d:1\n", ind++);        Continue        } int mmax=0;                    for (int i=0;i<n;i++) for (int. k=0;k<g[i].n;k++) for (int j=i+1;j<n;j++)                        for (int l=0;l<g[j].n;l++) {int ans=solve (g[i].p[k],g[j].p[l],n);                    if (ans > Mmax) mmax = ans;    } printf ("Case%d:%d\n", Ind++,mmax); } return 0;}


HDU3952 Fruit Ninja (geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.