(Shaped pressure) Brush (IV) (Light OJ 1018)

Source: Internet
Author: User
Tags cmath

http://www.lightoj.com/volume_showproblem.php?problem=1018 

Mubashwir returned home from the contest and got angry after seeing his hostel dusty. Who likes to see a dusty, after a brain storming programming contest? After checking a bit he found an old toothbrush in his class. Since The dusts is scattered everywhere, he's a bit confused what to do. So, he called Shakib. Shkib said that, ' with the brush recursively and clean all the dust, I am cleaning my dust in this way! '

So, Mubashwir got a bit confused, because it ' s just a tooth brush. So, he'll move the brush in a straight line and remove all the dust. Assume that the tooth brush is only removes the dusts which lie on the line. But since he had a tooth brush so, he can move the brush in any direction. So, he counts a move as driving the tooth brush in a straight line and removing the dusts in the line.

Now he wants to find the maximum number of moves to remove all dusts. You can assume that dusts is defined as 2D points, and if the brush touches a point, it ' s cleaned. Since he already had a contest, his head is messy. That's why he's wants your help.

Input

Input starts with an integer T (≤1000), denoting the number of test cases.

Each case starts with a blank line. The next line contains three integers N (1≤n≤16). n means that there is n dust points. Each of the next N lines would contain the integers Xi Yi denoting the coordinate of a dust unit. You can assume this ( -1000≤xi, yi≤1000) and all points is distinct.

Output

For each case, print the case number and the minimum number of moves.

sample Input output for Sample Input

2

 

3

0 0

1 1

2 2

 

3

0 0

1 1

2 3

Span style= "Font-family:simhei; Font-size:large; " >case 1:1

case 2:2


Main topic: give you n points, ask for the least line to cover all the pointsMemory Search:
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>using namespacestd;typedef unsignedLong LongLL;#defineMet (A, B) (Memset (A,b,sizeof (a)))Const intINF = 1e9+7;Const intMAXN = the;Const intMOD =9973;structnode{intx, y;} a[ -];intdp[(1<< -)], N;intline[ -][ -];///Line[i][j] Represents the point that is collinear with the segment IJintDasointSTA) {    if(dp[sta]!=-1)returnDp[sta]; Dp[sta]=INF; intCnt=0;  for(intI=0; i<n; i++)        if(sta& (1<<i)) cnt++; if(cnt==0)returndp[sta]=0; Else if(cnt<=2)returndp[sta]=1;  for(intI=0; i<n; i++)    {        if(sta& (1<<i))///Article I items        {             for(intj=i+1; j<n; J + +)            {                intW = (sta| LINE[I][J])-Line[i][j]; Dp[sta]= Min (Dp[sta], DFS (W) +1); }             Break; ///optimization, only one point in the STA can be found, line[i][j] will iterate over all the points after I to I        }    }    returnDp[sta];}intMain () {intT, icase =1; scanf ("%d", &T);  while(T--)    {        intI, J, K, K; scanf ("%d", &N); K= (1<<n)-1; Met (DP,-1); Met (line,0);  for(i=0; i<n; i++) {scanf ("%d%d", &a[i].x, &a[i].y); Line[i][i]= (1<<i); }         for(i=0; i<n; i++)         for(j=i+1; j<n; J + +)         for(k=0; k<n; k++)        {   ///determine if three points are collinear            if((a[i].x-a[k].x) * (a[i].y-a[j].y) = = (a[i].x-a[j].x) * (a[i].y-a[k].y)) LINE[I][J]+= (1<<k); } printf ("Case %d:%d\n", icase++, DFS (K)); }    return 0;}

First preprocess each line, select two points in each state that are not in the state, and then draw a line with two points as the endpoint for state transfer

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>using namespacestd;typedef unsignedLong LongLL;#defineMet (A, B) (Memset (A,b,sizeof (a)))Const intINF = 1e9+7;Const intMAXN = the;Const intMOD =9973;structnode{intx, y;} a[ -];vector<int>g[(1<< -)];intdp[(1<< -)], N;intline[ -][ -];///Line[i][j] Represents the point that is collinear with the segment IJintMain () {intT, icase =1, I, J;  for(i=0; i< (1<< -); i++)     for(j=0; j< -; J + +)    {        if((i& (1&LT;&LT;J)) = =0) G[i].push_back (j); } scanf ("%d", &T);  while(T--)    {        intK, K; scanf ("%d", &N); K= (1<<n)-1;        Met (DP, INF); Met (line,0);  for(i=0; i<n; i++) {scanf ("%d%d", &a[i].x, &a[i].y); Line[i][i]= (1<<i); }         for(i=0; i<n; i++)         for(j=i+1; j<n; J + +)         for(k=0; k<n; k++)        {   ///determine if three points are collinear            if((a[i].x-a[k].x) * (a[i].y-a[j].y) = = (a[i].x-a[j].x) * (a[i].y-a[k].y)) LINE[I][J]+= (1<<k); } dp[0] =0;  for(i=0; i<k; i++)        {            intLen =g[i].size (); intx=g[i][0], y;  for(j=0; j<len; J + +) {y=G[i][j]; Dp[i| Line[x][y]] = min (dp[i| Line[x][y]], dp[i]+1); }} printf ("Case %d:%d\n", icase++, Dp[k]); }    return 0;}/**230 3*/

(Shaped pressure) Brush (IV) (Light OJ 1018)

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.