zoukankan      html  css  js  c++  java
  • Lightoj 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

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/6/22 20:44:30
    File Name     :1018.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 1000010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    
    int dp[maxn],n,l[20][20];
    struct node{
        int x,y;
    }nod[20];
    bool Gx(node a,node b,node c){
        //int tmp=(a.x*b.y-a.y*b.x)+(b.x*c.y-b.y*c.x)+(c.x*a.y-c.y*a.x);
        //if(tmp==0)return true;
        if((a.x-b.x)*(c.y-b.y)-(a.y-b.y)*(c.x-b.x)==0)return true;
        return false;
    }
    int dfs(int s){
        if(dp[s]!=INF)return dp[s];
        int cnt=0;
        for(int i=0;i<n;i++)if(s&(1<<i))cnt++;
        if(cnt==0)return 0;
        if(cnt<=2)return 1;
        for(int i=0;i<n;i++){
            if(s&(1<<i)){
                for(int j=i+1;j<n;j++){
                    if(s&(1<<j))
                        dp[s]=min(dp[s],dfs(s-(s&l[i][j]))+1);
                }
                break;
            }
        }
        return dp[s];
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int T;
        cin>>T;
        for(int t=1;t<=T;t++){
            cin>>n;
            for(int i=0;i<n;i++)scanf("%d %d",&nod[i].x,&nod[i].y);
            for(int i=0;i<n;i++)l[i][i]=0;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    l[i][j]=(1<<i)|(1<<j);
                    for(int k=0;k<n;k++){
                        if(Gx(nod[i],nod[j],nod[k]))
                            l[i][j]|=(1<<k);
                        l[j][i]=l[i][j];
                    }
                }
            }
            int top=1<<n;
            memset(dp,INF,sizeof dp);
            dp[0]=0;
            printf("Case %d: %d
    ",t,dfs(top-1));
        }
        return 0;
    }
  • 相关阅读:
    .NET CORE QuartzJob定时任务+Windows/Linux部署
    .NET CORE 数据保护
    Docker容器间通信
    Docker加载本地证书
    转载-AppDomain详解
    JMeter尝鲜
    从String类型发散想到的一些东西
    npm源管理
    一张脑图整理Docker常用命令
    构造管“生”对象?析构管“埋”对象?C++中构造析构还没整明白?
  • 原文地址:https://www.cnblogs.com/pk28/p/5608686.html
Copyright © 2011-2022 走看看