记录编号 |
337856 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
__围栏问题 |
最终得分 |
100 |
用户昵称 |
rewine |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.050 s |
提交时间 |
2016-11-04 21:42:33 |
内存使用 |
0.32 MiB |
显示代码纯文本
#define pro __attribute__((optimize("-Os")))
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long lg;
namespace PROIO {
template <class T>
pro inline void read(T &x) {
register bool flag = 0;register char c;
while((c=getchar())>'9'||c<'0')
if(c == '-') flag = 1;
x = c-'0';
while((c=getchar())<='9'&&c>='0')
x = ((x<<1)+(x<<3))+c-'0';
if(flag) x = -x;
}
template <class T>
pro inline void write(register T x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x >= 10)
write(x/10);
putchar(x%10+'0');
}
}
using namespace PROIO;
#define MAXX 500009
#define inf 100000007
#define R register
int n,m,k;
lg ans = inf;
int t[20][20];
int maax = 0,may = 0,mix=inf,miy=inf;
struct data {
int x,y;
}a[20];
pro inline int min(R int a,R int b) {
return a < b ? a : b;
}
pro inline int man(R int a,R int b) {
return a > b ? a : b;
}
pro inline int js(bool ok) {
lg tmp = 0;
for(R int i = 1; i <= k; i++) {
maax = 0;may = 0;mix = inf;miy = inf;
if(t[i][0] == 0) break;
for(int j = 1; j<= t[i][0]; j++) {
R 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);
return tmp;
}
bool cmp(const data a,const data b) {
return a.x == b.x ? a.y<b.y:a.x<b.x;
}
pro inline void dfs(R int x) {
if(x == n+1) {
js(1);
return;
}
for(R 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]--;
}
}
pro inline void work() {
read(m);read(k);read(n);
for (int i = 1; i <= n; i++)
read(a[i].x),read(a[i].y);
sort(a+1,a+n+1,cmp);
dfs(1);
write(ans);
}
int main() {
freopen("xfence.in","r",stdin);
freopen("xfence.out","w",stdout);
work();
return 0;
}