UPC - 8839: Parallel Lines(DFS暴力)

 

贵有恒,何必三更起五更眠;最无益,莫过一日曝十日寒。

8839: Parallel Lines

时间限制: 10 Sec  内存限制: 128 MB
提交: 120  解决: 22
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Given an even number of distinct planar points, consider coupling all of the points into pairs.
All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point.
When lines are drawn connecting the two points of all the coupled point pairs, some of the drawn lines can be parallel to some others. Your task is to find the maximum number of parallel line pairs considering all the possible couplings of the points. 
For the case given in the first sample input with four points, there are three patterns of point couplings as shown in Figure B.1. The numbers of parallel line pairs are 0, 0, and 1, from the left. So the maximum is 1.

Figure B.1. All three possible couplings for Sample Input 1
For the case given in the second sample input with eight points, the points can be coupled as shown in Figure B.2. With such a point pairing, all four lines are parallel to one another. In other words, the six line pairs (L1, L2), (L1, L3), (L1, L4), (L2, L3), (L2, L4) and (L3, L4) are parallel. So the maximum number of parallel line pairs, in this case, is 6.

 

输入

The input consists of a single test case of the following format.
m
x1 y1
.
.
.
xm ym

Figure B.2. Maximizing the number of parallel line pairs for Sample Input 2
The first line contains an even integer m, which is the number of points (2 ≤ m ≤ 16). Each of the following m lines gives the coordinates of a point. Integers xi and yi (−1000 ≤ xi ≤ 1000,−1000 ≤ yi ≤ 1000) in the i-th line of them give the x- and y-coordinates, respectively, of the i-th point.
The positions of points are all different, that is, xi ≠ xj or yi ≠ yj holds for all i ≠ j. Furthermore, No three points lie on a single line.

输出

Output the maximum possible number of parallel line pairs stated above, in one line.

 

样例输入

4
0 0
1 1
0 2
2 4

 

样例输出

1

 

来源/分类

ICPC 2017 Japan Tsukuba 

 

#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,j,k) for(int i=j;i<k;i++)
#define per(i,j,k) for(int i=j;i<=j;i++) 
const int maxn = 20;
typedef long long ll;
int a[maxn],b[maxn];
int vis[maxn];
int n,ans;
vector <pair<int ,int> >  que;
void get_max()
{
    int sum=0;
    rep(i,0,que.size())
    {
        int x1= a[que[i].first]-a[que[i].second];
        int y1= b[que[i].first]-b[que[i].second];
        rep(j,0,que.size()) 
        {
            if(i==j) continue;
            int x2 = a[que[j].first]-a[que[j].second];
            int y2 = b[que[j].first]-b[que[j].second];
            if(x1*y2==y1*x2) sum++;
        }
    }
    ans = max(ans,sum/2);
}
void dfs(int cur)
{
     if(cur==n){
        get_max();
        return;
     }
     if(vis[cur]) return dfs(cur+1);   //用过的点将继续找 
     rep(i,0,n)
     {
            if(!vis[i]&&i!=cur) 
            {
                que.push_back(make_pair(cur,i)); 
                vis[i]= vis[cur] =1;              //每次找两个可行点连成一条线       
                dfs(cur+1);
                que.pop_back(); 
                vis[i]=vis[cur]=0;               //遍历所有
            }
     }
}

int main(void)
{
    IO
    while(cin>>n)
    {
    memset(vis,0,sizeof(vis)); 
    ans=0;
    rep(i,0,n)   cin>>a[i]>>b[i];
    dfs(0);
    cout<<ans<<endl;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
检查错误原因 creating directory /data/primary/gpseg0 ... ok creating subdirectories ... ok selecting default max_connections ... 750 selecting default shared_buffers ... 125MB selecting default timezone ... Asia/Shanghai selecting dynamic shared memory implementation ... posix creating configuration files ... ok creating template1 database in /data/primary/gpseg0/base/1 ... child process was terminated by signal 9: Killed initdb: removing data directory "/data/primary/gpseg0" 2023-06-08 08:53:53.568563 GMT,,,p22007,th-604637056,,,,0,,,seg-10000,,,,,"LOG","00000","skipping missing configuration file ""/data/primary/gpseg0/postgresql.auto.conf""",,,,,,,,"ParseConfigFile","guc-file.l",563, 20230608:16:54:12:021728 gpcreateseg.sh:VM-0-5-centos:gpadmin-[INFO]:-Start Function BACKOUT_COMMAND 20230608:16:54:12:021728 gpcreateseg.sh:VM-0-5-centos:gpadmin-[INFO]:-End Function BACKOUT_COMMAND 20230608:16:54:12:021728 gpcreateseg.sh:VM-0-5-centos:gpadmin-[INFO]:-Start Function BACKOUT_COMMAND 20230608:16:54:12:021728 gpcreateseg.sh:VM-0-5-centos:gpadmin-[INFO]:-End Function BACKOUT_COMMAND 20230608:16:54:12:021728 gpcreateseg.sh:VM-0-5-centos:gpadmin-[FATAL][0]:-Failed to start segment instance database VM-0-5-centos /data/primary/gpseg0 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-End Function PARALLEL_WAIT 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-End Function PARALLEL_COUNT 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-Start Function PARALLEL_SUMMARY_STATUS_REPORT 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:------------------------------------------------ 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-Parallel process exit status 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:------------------------------------------------ 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-Total processes marked as completed = 0 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-Total processes marked as killed = 0 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[WARN]:-Total processes marked as failed = 1 <<<<< 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:------------------------------------------------ 20230608:16:54:12:019435 gpinitsystem:VM-0-5-centos:gpadmin-[INFO]:-End Function PARALLEL_SUMMARY_STATUS_REPORT FAILED:VM-0-5-centos~6000~/data/primary/gpseg0~2~0
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值