zoukankan      html  css  js  c++  java
  • 1018

    1018 - Brush (IV)
    Time Limit: 2 second(s) Memory Limit: 32 MB

    Mubashwir returned home from the contest and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming contest? After checking a bit he found an old toothbrush in his room. Since the dusts are scattered everywhere, he is a bit confused what to do. So, he called Shakib. Shkib said that, 'Use 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 will move the brush in a straight line and remove all the dust. Assume that the tooth brush only removes the dusts which lie on the line. But since he has 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 are 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 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 are N dust points. Each of the next N lines will contain two integers xi yi denoting the coordinate of a dust unit. You can assume that (-1000 ≤ xi, yi ≤ 1000) and all points are 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

    Case 1: 1

    Case 2: 2


    PROBLEM SETTER: AKM MUBASHWIR ALAM
    SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASE
    题意:给你n个点,然后要你画直线覆盖这些点,问你最少需要几条线可以覆盖所有的点。
    思路:状态压缩dp;
    两个点决定一条直线,我们先打表将两点确定的直线和在这个直线上的点处理出来,然后 dp[i]表示 在 状态i时最少要 用的 直线 数,dp[de]=min(dp[i]+1,dp[de]);
    那么说下状态i表示的是二进制数,那么i中的0为未覆盖的,1为已经覆盖的,那么当i中当且只有一个1时那么 这时直线数应该为1。那么枚举未覆盖 的点用上面的状态转移 方程 就行,最后dp[(1<<n)-1]就为答案。
      1 #include<stdio.h>
      2 #include<algorithm>
      3 #include<string.h>
      4 #include<stdlib.h>
      5 #include<queue>
      6 #include<iostream>
      7 #include<math.h>
      8 using namespace std;
      9 typedef struct pp
     10 {
     11     int x;
     12     int y;
     13 } ss;
     14 ss ans[200];
     15 int line[20][20];
     16 int ck[75550][20];
     17 int dp[70000];
     18 bool xian(pp a,pp b)
     19 {
     20     return (a.x*b.y-a.y*b.x)==0?true:false;
     21 }
     22 int main(void)
     23 {
     24     int i,j,k;
     25     scanf("%d",&k);
     26     int c;
     27     int n,m;
     28     for(i=0; i<(1<<16); i++)
     29     {
     30         int cc=i;
     31         int u=0;
     32         int t=1;
     33         while(u<16)
     34         {
     35             if(cc%2==0)
     36             {
     37                 ck[i][t]=u;
     38                 t++;
     39             }
     40             cc/=2;
     41             u++;
     42         }
     43         ck[i][0]=t-1;
     44     }
     45     for(c=1; c<=k; c++)
     46     {
     47 
     48         memset(line,0,sizeof(line));
     49         fill(dp,dp+65550,100);
     50         scanf("%d",&n);
     51         int xx;
     52         int yy;
     53         xx=0;
     54         yy=0;
     55         for(i=0; i<n; i++)
     56         {
     57             scanf("%d %d",&ans[i].x,&ans[i].y);
     58             if(ans[i].x!=0||ans[i].y!=0)
     59                 xx=ans[i].x,yy=ans[i].y;
     60         }
     61         for(i=0; i<n; i++)
     62         {
     63             for(j=i+1; j<n; j++)
     64             {
     65                 line[i][j]|=(1<<i);
     66                 line[i][j]|=(1<<j);
     67                 for(int s=0; s<n; s++)
     68                 {
     69                     ss nn;
     70                     nn.x=ans[i].x-ans[j].x;
     71                     nn.y=ans[i].y-ans[j].y;
     72                     ss mm;
     73                     mm.x=ans[s].x-ans[j].x;
     74                     mm.y=ans[s].y-ans[j].y;
     75                     bool ask=xian(nn,mm);
     76                     if(ask)
     77                         line[i][j]|=(1<<s);
     78                 }
     79                 line[j][i]=line[i][j];
     80             }
     81         }
     82         int ak=(1<<n)-1;
     83         dp[0]=0;
     84         for(i=0; i<=ak; i++)
     85         {
     86             int uu=i;
     87             int cn=0;
     88             cn=ck[i][0];
     89             cn-=(16-n);
     90             if(n-cn==1)
     91               dp[i]=1;
     92             if(cn>=2)
     93             {
     94                 int s;
     95                 for(j=1; j<=1; j++)
     96                 {
     97                     for(s=j+1; s<=cn; s++)
     98                     {
     99                         int v;
    100                         int t=line[ck[i][j]][ck[i][s]];
    101                         int de=i;
    102                         de|=t;
    103                         dp[de]=min(dp[de],dp[i]+1);
    104                     }
    105                 } 
    106             }
    107         }
    108         printf("Case %d: ",c);
    109         printf("%d
    ",dp[ak]);
    110     }
    111     return 0;
    112 }
     
    油!油!you@
  • 相关阅读:
    pycharm连接数据库
    python之csv操作
    python网络爬虫之爬取图片
    行人重识别在深度学习方法的研究进展整理
    CVPR2016_Learning Deep Feature Representations with Domain Guided Dropout for Person Re-identification
    [转载]研究生导师:这种学生,才是我眼中的科研好苗子!
    [论文笔记]CVPR2016_Person re-identifcation by multi-channel parts-based cnn with improved triplet loss function
    [论文笔记]ECCV2016_A Siamese Long Short-Term Memory Architecture for Human Re-Identication
    LSTM学习理解资料
    [论文笔记]PersonNet: Person Re-identification with Deep Convolutional Neural Networks
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5599308.html
Copyright © 2011-2022 走看看