[NOIP2016] Angry Birds D2 T3 pressure DP

Source: Internet
Author: User

[NOIP2016] Angry Birds D2 t3description

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 n/3+1? Only birds can destroy all the piglets.

If m=2, then this level will be satisfied: there must be an optimal solution, in which a bird wiped out at least N/3?

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.

Above, the symbol, C, and ? c, respectively, for the C-up rounding and rounding down


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 Input2 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.00Sample Output1 1HINT

"Sample Interpretation"
There are two levels in this set of data.
The first level is the same as in the "Problem description", where 2 piglets are located (1.00,3.00) and (3.00,3.00), and only one flight trajectory of y =-x2 + 4x is emitted.
There are 5 little pigs in the second level, but after observation we can find that their coordinates are on the parabola y =-x2 + 6x, so Kiana only need to launch a bird to kill all the piglets.


The puzzle: The examination room wanted to use the BFS, the result of a pass, oneself also patted a bunch of data (human flesh to pat), feel can take a dozens of cent to turn up, the result decisive explode zero, already tear Ben.

Later found to be a pressure DP, at the beginning of the thought of the enumeration subset to do, (The Complexity O (2^n * tot), tot is all can kill the pig), the result tle, so can only enumerate parabolic.

In the current state, each time the enumeration of two points, the parabolic analytic formula, and then enumerate the other points on the parabolic, the complexity O (2^n * n^3), so that after a few points will be tle, how to do?

So thought can be preprocessed for any two points, what points and the two points on the same parabola, the state recorded, then immediately went to a heavy cycle, into O (2^n * n^2), AC.

#include <cstdio>#include<cstring>#include<cmath>#include<iostream>using namespacestd;intN,m,tot;Doublex[ -],y[ -];intf[1<< -],v[ -][ -];BOOLeqDoubleADoubleb) {    returnFabs (A-B) <0.000001;}voidWork () {scanf ("%d%d",&n,&m); inti,j,k; Doublea,b,a1,b1;  for(i=1; i<=n;i++) scanf ("%LF%LF",&x[i],&Y[i]); Memset (F,0x3f,sizeof(f)); f[0]=0;  for(i=1; i<=n;i++)//pretreatment{v[i][0]=1<<i-1;  for(j=1; j<i;j++) {V[i][j]=v[i][0]; A1= (Y[j]*x[i]-y[i]*x[j])/(x[j]*x[j]*x[i]-x[i]*x[i]*X[j]); B1= (Y[j]-a1*x[j]*x[j])/X[j]; if(a1>=0)Continue; V[I][J]+=1<<j-1;  for(k=1; k<j;k++) {a= (Y[k]*x[i]-y[i]*x[k])/(x[k]*x[k]*x[i]-x[i]*x[i]*X[k]); b= (Y[k]-a*x[k]*x[k])/X[k]; if(eq (A,A1) &&eq (B,B1)) v[i][j]+=1<<k-1; }        }    }     for(i=1;i<1<<n;i++)    {         for(j=1;(1<<j-1) <=i&&j<=n;j++)        {            if((i& (1<<j-1))!=1<<j-1)Continue; F[i]=min (f[i],f[i-v[j][0]]+1);  for(k=1; k<j;k++)            {                if((i& (1<<k-1))!=1<<k-1)Continue; F[i]=min (f[i],f[i& (~v[j][k])]+1); //Delete all the points on the same parabolic line directly with the J,k}}} printf ("%d\n", f[(1<<n)-1]);}intMain () {intT; scanf ("%d",&T);  while(t--) work (); return 0;}

[NOIP2016] Angry Birds D2 T3 pressure DP

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.