记录编号 337903 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 __围栏问题 最终得分 100
用户昵称 GravatarLethur 是否通过 通过
代码语言 C++ 运行时间 0.088 s
提交时间 2016-11-04 22:04:22 内存使用 0.29 MiB
显示代码纯文本
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <stdio.h> 
    #include <algorithm>
     
     
    using namespace std;
    typedef long long lg;
     
    #define MAXX 500009
    #define MOD 100000007
     
    int n,m,k;
    lg ans = 10000000;
    int t[20][20];
    int maax = 0,may = 0,mix=1000000,miy=10000000;
    struct data {
    	int x,y;
    }a[20];
     
    double start;
     
    inline int js(bool ok) {
    	lg tmp = 0;
    	for(int i = 1; i <= k; i++) {
         maax = 0;may = 0;mix=10000000;miy=10000000;
         if(t[i][0] == 0)  break;
    	 for(int j = 1; j<= t[i][0]; j++) {
    	 	int tt = t[i][j];
    	 	mix = min(mix,a[tt].x);
    	    miy = min(miy,a[tt].y);
    	    maax = max(maax,a[tt].x);
    	    may = max(may,a[tt].y);
    	 }
    	 tmp += ((maax-mix+1)+(may-miy+1))*2;
        }
    	if(ok)ans = min(ans,tmp);
    //	double end=GetTickCount();
    //cout<<end<<endl;
      //if(ans == 2258)cout<<end-start;
      //cout<<"ghgf";
    //	if(end - start >= 2995){
    //		printf("%d",ans);
    	//	exit(0);
    //	}
    	return tmp;
        //printf("The difference is: %f seconds\n",difftime(second,first)); 
    }
     
    bool cmp(const data a,const data b) {
    	return a.x == b.x ? a.y<b.y:a.x<b.x;
    }
     
    inline void dfs(int x) {
    	if(x == n+1) {
    		js(1);
    		return;
    	}
    	for(int i = 1;i <= k;i++) {
    		if(t[i-1][0] == 0 && i != 1) break;
    		t[i][++t[i][0]] = x;
    		if(js(0) < ans)dfs(x+1);
    		t[i][0]--;
    	}
    }
     
    void work() {
    	scanf("%d%d%d",&m,&k,&n);
    	for (int i = 1; i <= n; i++) {
    	 scanf("%d%d",&a[i].x,&a[i].y);
    	  mix = min(mix,a[i].x);
    	  miy = min(miy,a[i].y);
    	  maax = max(maax,a[i].x);
    	  may = max(may,a[i].y);
        }
        sort(a+1,a+n+1,cmp);
    	if(k == 1) {
    		cout<<((maax-mix+1)+(may-miy+1))*2;
    		return;
    	}
    	if(n == 1) {
    		cout<<"4";
    		return;
    	}
    	dfs(1);
    	printf("%d",ans);
    }
     
    int main() {
        //start = GetTickCount();  
    	freopen("xfence.in","r",stdin);
    	freopen("xfence.out","w",stdout);
    	work();
    	return 0;
    }