"noip2016" Angry Birds

Source: Internet
Author: User

Title Description

Kiana recently 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), each time Kiana can use it to the first quadrant to launch a red bird, the birds flying trajectory is shaped like the y=ax2+bx curve, where a, B is the Kiana specified parameters, and must meet the a<0.

When the bird falls back to the ground (i.e. the x-axis), it disappears instantly.

In a certain level of the game, there are n green piglets in the first quadrant of the plane, where the xi,yi is in the coordinates of the piglet.

If the flight path of a bird passes through (xi,yi), then the first pig will be wiped out, and the bird will continue to fly along the original trajectory;

If the flight path of a bird does not pass (Xi,yi), then the whole process of flying the bird will not have any effect on the first piglet.

For example, if two piglets were located (1,3) and (3,3), Kiana could choose to launch a bird with a flying trajectory of y=-x2+4x, so that two little pigs would 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 difficult for Kiana, so Kiana also entered some mysterious instructions to make it easier to complete the game. These instructions will be detailed in the "input format".

Assuming that the game has a total of t 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.


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

Enter the information for this T-level in turn. The first row of each level contains two non-negative integer n,m, each representing the number of piglets in the level and the mysterious instruction type of the Kiana input. In the next n rows, the line I contains two positive real numbers (Xi,yi), which indicates that the first piglet coordinates are (xi,yi). The data guarantees that there are no two pigs in the same level with exactly the same coordinates.

If m=0, indicates that Kiana has entered an instruction that does not have any effect.
If m=1, then this level will be satisfied: at most with n/3+1 only birds can destroy all piglets.
If the m=2, then this level will be satisfied: there must be an optimal solution, in which a bird killed at least n/3 pigs.

Guaranteed 1<=n<=18,0<=m<=2,0<xi,yi<10, the real number in the input is retained to two digits after the decimal point.


Output one line of answers to each level.

Each line of the output contains a positive integer that represents the minimum number of birds needed to destroy all piglets in the corresponding level.

Sample input

22 01.00 3.003.00 3.005 21.00 5.002.00 8.003.00 9.004.00 8.005.00 5.00

Sample output



Pressure DP. state[i] [j] indicates the state of the pig through the parabola of the i,j two pigs; dp[i] indicates the number of birds required for the current pig's status of I, of which 1 indicates that the pig in this position has been beaten, and 0 indicates that it has not been hit.

#include <cmath>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#definell Long LongConst intMaxn= (1<< +);Const Doubleeps=1e-8;intn,m,t,state[ -][ -],judge[ -],DP[MAXN];structpig{Doublex, y;} a[ -];intCalcintD1,intD2) {    Doublex1=a[d1].x,y1=a[d1].y; DoubleX2=a[d2].x,y2=a[d2].y; if(Fabs (X1-X2) <=eps)return 0; Doubletx=x1*x1*x2-x2*x2*x1,ty=y1*x2-y2*X1; Doubleaa=ty/tx,b= (Y1-AA*X1*X1)/X1; if(aa>=0)return 0; intres=0; JUDGE[D1]=judge[d2]=1;  for(intI=1; i<=n;i++){        Doublex=a[i].x,y=a[i].y; if(Fabs (AA*X*X+B*X-Y) <EPS) Res|=1<< (I-1), dp[1<< (I-1)]=dp[res]=1; }    returnRes;} Template<typename t>voidRead (t&AA) {    Charcc ll Ff;aa=0; Cc=getchar (); ff=1;  while((cc<'0'|| Cc>'9') &&cc!='-') cc=GetChar (); if(cc=='-') ff=-1, cc=GetChar ();  while(cc>='0'&&cc<='9') aa=aa*Ten+cc-'0', cc=GetChar (); AA*=ff;}intMain () {read (T);  while(t--) {memset (DP,127,sizeof(DP)); memset (judge,0,sizeof(judge));        Read (n), read (m);  for(intI=1; i<=n;i++) {scanf ("%LF%LF",&a[i].x,&a[i].y); dp[1<< (I-1)]=1; }         for(intI=1; i<=n;i++)         for(intj=i+1; j<=n;j++) State[i][j]=Calc (i,j);  for(intI=1;i< (1&LT;&LT;N); i++)         for(intj=1; j<=n;j++){            if((I>> (J-1)) &1))Continue; if(!Judge[j]) {Dp[i| (1<< (J-1))]=min (dp[i|1<< (J-1)],dp[i]+1); Continue; }             for(intk=j+1; k<=n;k++){                if((I>> (K-1)) &1))Continue; Dp[i|state[j][k]]=min (dp[i|state[j][k]],dp[i]+1); } dp[i| (1<< (J-1))]=min (dp[i|1<< (J-1)],dp[i]+1); } printf ("%d\n", dp[(1<<n)-1]); }    return 0;}

"noip2016" 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.