2018 Tenka1 D - Crossing
Table of Contents
Problem description
Problem analysis
If , it can be seen that
1 2
2 3
3 1
satisfies the conditions. When or , there are no subsets satisfying the conditions. If , result can be following
1 2 3
2 3 4
3 4 5
4 5 6
It can be assumed that every subset has same elements. Proof as following:
Assume has sets satisfy the conditions; -th of them is . Set is the number of elements. Let .
First, we consider . Because of condition
Any two of the sets have exactly one element in common.
We kmow that since each element in occur once from .
The other condition can be seen that
Each of the integers contained excatly two of sets .
It can be concluded that . So, it is 'OK' when .
How shoule we order ? One of my solutions can be seen that
AC code
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF 0xc0c0c0c0
#define NINF 0x3f3f3f3f
#define FOR(i, a, b) for((i)=a; i<b; ++(i))
#define EFOR(i, a, b) for((i)=a; i>b; --(i))
#define MLC(n, type) (type*)malloc(n*sizeof(type))
#define CLC(n, type) (type*)calloc(n, sizeof(type))
#define MAXN 100000
void myPrint(int rows, int cols) {
int i,j;
int cur = 0;
int end = 1;
printf("%d\n", rows);
for (i = 1; i <= rows; ++i) {
printf("%d ", cols);
for (j = 1; j < i; ++j) {
if (j == 1) {
printf("%d ", i-1);
cur = i - 1;
}
else {
cur += cols - j + 1;
printf("%d ", cur);
}
}
for (; j <= cols; ++end, ++j) {
printf("%d ", end);
}
printf("\n");
}
}
void solver(int n) {
int i;
int h = sqrt((n<<1));
if (h*(h+1) != (n<<1)) {
printf("No\n");
return;
}
printf("Yes\n");
myPrint(h+1, h);
}
int main() {
int n;
scanf("%d", &n);
solver(n);
return 0;
}