NOIP 2016 Angry Birds

Source: Internet
Author: User
Tags first row

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=ax^2+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=-x^2+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.

Input/output format
Input format:

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 a bird 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 a pig.

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 symbols and respectively represent the rounding up and rounding down of C

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 needed to destroy all piglets in the corresponding level.

Input/Output sample

Input Sample # #:
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

Sample # # of output:

Input Sample #:
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 #:

Input Sample # #:
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 # #:


"Sample Interpretation 1"

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 =-x^2 + 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 =-x^2 + 6x, so Kiana only need to launch a bird to kill all the piglets.

Yin God Orz, this problem I searched one hours search 60, I yin 60 line to fix.

My non-positive solution is deep search, pre-treatment of n pigs and T-only bird relationship, if the first pig can be hit by the J-Bird, then the two even a side, the problem into how to use the fewest birds to cover all the pigs. Then the blind search will not prune, so glorious tle. Of course some students can also search out, I am not very good ah ...

The positive solution is a pressure DP. Pre-F[I][J], indicating that the first pig and the first J Pig was knocked down by a bird, the bird can also hit which pigs (0 means no, 1 means to hit, in binary notation, including i,j two pigs).
Enumerate all the states of 0~1<< (N-1), first to find out the first not to be knocked out of the pig K (play late to fight), and then enumerate K after the pig, equivalent to enumerate the parabola containing the pig K, with the previous state to update the back state, use or operation.

The core code is as follows
Fo (i,0, (1<<n)-2)//enumeration status
    while ((1<<k) &i) k++;k++; The K-Pig is the first pig that has not been killed
    dp[i| ( 1<< (k-1))]=min (dp[i| ( 1<< (k-1))],dp[i]+1);
    Fo (j,k+1,n) 
      dp[i|f[k][j]]=min (dp[i|f[k][j]],dp[i]+1);
dp[(1<<n)-1] That's the answer.


NOIP 2016 Angry Birds (like pressure dp) #include <cmath> #include <cstdio> #include <cstring> #include <iostream > #include <algorithm> #define LL Long long #define M (a) memset (a,0,sizeof a) #define FO (i,j,k) for (i=j;i<=k;i+
+) using namespace Std;
const double EPS=1E-10;
int t,n,m;
Double x[20],y[20];  int f[20][20],dp[1<<19];
    F[I][J] means that i,j two pigs will be able to lay a small bird can also be laid which pig inline void calc () {int i,j,k;
          Fo (i,1,n) fo (j,i+1,n) {double x11=x[i],y11=y[i],x22=x[j],y22=y[j];
          Double a= (X11*Y22-X22*Y11)/(x11*x22* (x22-x11));
          Double b= (X11*X11*Y22-X22*X22*Y11)/(x11*x22* (x11-x22));
          if (a>=0) continue;
              Fo (k,1,n) {double tmp=a*x[k]*x[k]+b*x[k];
          if (y[k]-eps<=tmp && tmp<=y[k]+eps) f[i][j]|= (1<< (k-1));
    }}}-inline int dynamic () {int i,j,k;
        Fo (i,0, (1<<n)-2) {k=0; while ((1<<k) &i)k++;k++; The K-Pig is the first pig that has not been killed dp[i| ( 1<< (k-1))]=min (dp[i| (
        1<< (k-1))],dp[i]+1);
    Fo (j,k+1,n) dp[i|f[k][j]]=min (dp[i|f[k][j]],dp[i]+1);
} return dp[(1<<n)-1];
    } int main () {int i,j;
    scanf ("%d", &t);
        while (t--) {M (f);
        memset (dp,0x3f,sizeof DP);
        scanf ("%d%d", &n,&m);
        Fo (i,1,n) scanf ("%lf%lf", &x[i],&y[i]);
        Calc ();
    printf ("%d\n", dynamic ());
} return 0; }/* 1 5 0 2.72 2.72 2.72 3.14 3.14 2.72 3.14 3.14 5.00 5.00 *

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: 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.