Angry Birds.

Source: Internet
Author: User

Title Description

KianaRecently addicted to a magical game can not extricate themselves.

In short, the game is done on a flat surface.

There is a slingshot located at (0,0) (0,0), each time Kiana it can be used to launch a red bird in the first quadrant, the birds flying trajectory are shaped like y=ax^2+bxy=ax2+bx curve, wherein the A,BA,B is the Kiana specified parameters, and must meet a < 0a <0,a,ba,b are real numbers.

When the bird falls back to the ground (that is, the XX axis), it disappears instantly.

In a certain level of the game, the first quadrant of the plane has an nn only green pig, where the second pig is located in the coordinates of \left (x_i,y_i \right) (Xi?,yi?).

If a bird's trajectory passes through the \left (x_i, y_i \right) (xi?,yi?), then the second pig will be wiped out, and the bird will continue to fly along the original trajectory;

If a bird's trajectory does not pass through \left (x_i, y_i \right) (xi?,yi?), then the whole process of flying the bird will not have any effect on the second pig.

For example, if two piglets are located in (1,3) (1,3) and (3,3) (3,3), Kiana you can choose to launch a bird with a flight trajectory of y=-x^2+4xy=?x2+4x so that two little pigs will be wiped out with the bird.

And the purpose of this game is to kill all the piglets by launching a bird.

Each level of this magical game is Kiana difficult to find, so I Kiana 've entered some cryptic instructions to make it easier for you to complete the game. These instructions will be detailed in the "input format".

Suppose this game has a total of TT levels, now Kiana want to know, for each level, at least the number of birds to be fired to destroy all the pigs. Since she won't count, I hope you'll tell her.

Input/output format

Input format:

The first line contains a positive integer, TT, that represents the total number of levels in the game.

Enter the information for this TT level in turn. The first row of each level contains two non-negative integer n,mn,m, each representing the number of piglets in the level and the mysterious instruction type of the Kiana input. In the next NN line, line II contains two positive real numbers x_i,y_ixi?,yi, indicating that the second-only piglet coordinates are (x_i,y_i) (Xi?,yi?). The data guarantees that there are no two pigs in the same level with exactly the same coordinates.

If m=0m=0, indicates that Kiana an instruction has been entered that does not have any effect.

If m=1m=1, this level will be fulfilled: up to \lceil N/3 + 1 \rceil?n/3+1? A little bird can destroy all the piglets.

If the m=2m=2, then this level will be satisfied: there must be an optimal solution, wherein a bird destroyed at least \lfloor n/3 \RFLOOR?N/3? Little Piggy.

Guaranteed 1\leq n \leq 181≤n≤18,0\leq m \leq 20≤m≤2,0 < X_i,y_i < 100<xi?,yi?<10, the real number in the input is reserved to two digits after the decimal point.

Above, the symbol \lceil C \rceil?c? and \lfloor C \rfloor?c? For CC rounding up and down respectively, for example: \lceil 2.1 \rceil = \lceil 2.9 \rceil = \lceil 3.0 \rceil = \lfloor 3.0 \rfloor = \lfloor 3.1 \rfloo r = \lfloor 3.9 \rfloor = 3?2.1?=?2.9?=?3.0?=?3.0?=?3.1?=?3.9?=3.

Output format:

Output one line of answers to each level.

Each line of the output contains a positive integer that represents the minimum number of birds required for all piglets to be eliminated in the corresponding level.

Input/Output sample

Input Sample # #: copy

2
2 0
1.00 3.00
3.00 3.00
5 2
1.00 5.00
2.00 8.00
3.00 9.00
4.00 8.00
5.00 5.00

Output Example # #: replication

1
1

Input Example #: copy

3
2 0
1.41 2.00
1.73 3.00
3 0
1.11 1.41
2.34 1.79
2.98 1.49
5 0
2.72 2.72
2.72 3.14
3.14 2.72
3.14 3.14
5.00 5.00

Output Example # #: Copy

2
2
3

Input Sample # #: Copy

1
10 0
7.16 6.28
2.02 0.38
8.33 7.78
7.68 2.09
7.46 7.86
5.77 7.44
8.24 6.72
4.42 5.11
5.42 7.79
8.15 4.99

Output Sample # #: Copy

6

Description

"Sample Interpretation 1"

There are two levels in this set of data.

The first level is the same as in the "Problem description", where 22 piglets are in (1.00,3.00) (1.00,3.00) and (3.00,3.00) (3.00,3.00), and only one flight path is emitted as Y =-x^2 + 4xy=?x2+ 4x of birds can destroy them.

There are 55 piglets in the second level, but after observation we can find that their coordinates are on the parabolic y =-x^2 + 6xy=?x2+6x, so Kiana only one bird can be fired to kill all the piglets.

"Data Range"

\ (O (tn^22^n) \)
\ (= 5*18^2*18*2\)
\ (=424673280\)

On the importance of faith for learning Oi (...)

\ (n \leq 18\) long on a face-like pressure ah no

\ (n^3\) brute force every bird can hit the state pressure in the array \ (w\) , When it's time to move. In each state, enumerate \ (w\) to update other states. Since every sub state of this state has been cycled, the answer must now be the optimal solution.

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include < Cstring> #define XS 0.000001using namespace Std;int i,m,n,j,k,a[1000001],t,w[600000],f[600000];d ouble d[20][2],r[ 20][20];void xxyy (double &a,double &b,double x1,double y1,double x2,double y2) {a= y1/(x1* (x1-x2))-y2/(x2* (x1    -X2)); b= (Y1*X2)/(X1* (X2-X1))-(X1*y2)/(x2* (X2-X1));}    BOOL PD (double a,double b) {double c=a-b;      if (c<0) c*=-1;    if (C&LT;XS) return 1; return 0;}    int main () {scanf ("%d", &t);        for (; t;t--) {memset (w,0,sizeof (w));                memset (F,0x3f,sizeof (f));        scanf ("%d%d", &n,&m);        for (i=1;i<=n;i++) scanf ("%lf%lf", &d[i][0],&d[i][1]);                for (i=0;i<n;i++) w[++w[0]]=1<<i;                for (i=1;i<=n;i++) for (j=i+1;j<=n;j++) if (!PD (D[i][0],d[j][0])) {double a1,b1;                int z= (1<< (i-1)) + (1<< (j-1)); XxyyA1,B1,D[I][0],D[I][1],D[J][0],D[J][1]);                if (a1>=0) continue;                    for (int l=j+1;l<=n;l++) {if (PD (D[i][0],d[l][0]) | | | PD (D[J][0],D[L][0])) continue;                    Double a2,b2;                    XXYY (a2,b2,d[i][0],d[i][1],d[l][0],d[l][1]);                if (PD (A1,A2) && PD (B1,B2)) z+= (1<< (L-1));            } w[++w[0]]=z;        } f[0]=0; For (i=0;i<= (1<< (n-1)), i++) if (f[i]!=0x3f3f3f3f) for (j=1;j<=w[0];j++) f[i | w[j]]=min (F[i | w[j]],f[        I]+1);    printf ("%d\n", f[(1<<n)-1]); }}

Angry Birds

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.