UOJ#283. 直径拆除鸡

UOJ#283. 直径拆除鸡

Code：

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 50;
typedef pair<int, int> P;
#define fi first
#define se second
#define mk make_pair
typedef vector<P> VecP;

int n, m;
VecP Ans;

int Calc(int len) {
int tmp = n, res = 0;
for(int i = len; i >= 3; i -= 2) res += tmp, tmp -= i;
res += tmp;
return res;
}

void Out(int len) {
int nw = 0, lasmd = -1;
for(int i = len; i >= 3; i -= 2) {
int st = ++nw, las = st, md;
for(int j = 2; j <= i; j++) {
Ans.push_back( mk(las, ++nw) );
las = nw;
if(j == (i + 1) / 2) md = nw;
}
if(~lasmd) Ans.push_back( mk(lasmd, md));
lasmd = md;
}
while(nw < n) {
Ans.push_back( mk(++nw, lasmd) );
}
for(int i = 0; i < (int) Ans.size(); i++) printf("%d %d\n", Ans[i].fi, Ans[i].se);
exit(0);
}

int main() {
scanf("%d%d", &n, &m);
if(n == 1) return 0;
if(n == 2) return puts("1 2"), 0;
if(n == 3) return puts("1 2"), puts("2 3"), 0;
int up = floor( sqrt(n * 4) ) - 1;
for(int i = 3; i <= up; i += 2) {
if(Calc(i) >= m) Out(i);
}
assert(0);
return 0;
}

posted @ 2019-04-17 19:12  Apocrypha  阅读(217)  评论(0编辑  收藏  举报