【2020牛客多校】2020牛客暑期多校訓練營(第二場)D-Points Construction Problem——構造
阿新 • • 發佈:2020-07-18
D-Points Construction Problem
晚點時間再更新具體思路
思路
- 先放一個\(2*2\)的矩陣
- 向上/右擴充套件
- 完善矩陣
- 向右/上擴充套件
- 完善矩陣
- 重複2-6直到足夠
- 輸出
AC code
#include <bits/stdc++.h> using namespace std; bool flag[60][60]; void print(int n) { if (n < 0) { cout << "No" << endl; return; } cout << "Yes" << endl; while (n) { cout << n * 100 << " " << n * 100 << endl; n--; } for (int i = 0; i < 60; ++i) for (int j = 0; j < 60; ++j) if (flag[i][j]) cout << i + 1 << " " << j + 1 << endl; } void solve() { int T; cin >> T; for (int ts = 0; ts < T; ++ts) { int n, m; cin >> n >> m; int target = (n * 4 - m) / 2; if ((n * 4 - m) & 1) { n = -1; print(n); continue; } memset(flag, 0, sizeof(flag)); if (target < 4) { int x = 2; flag[1][1] = true; n--; while (target && n >= 0) { flag[x][1] = true; x++; target--; n--; } print(n); continue; } flag[1][1] = flag[1][2] = flag[2][1] = flag[2][2] = true; n -= 4; target -= 4; int l = 3, r = 3; while (target > 2) { // 右擴充套件 flag[1][l] = true; flag[2][l] = true; l++; target -= 3; n -= 2; int len = 3; while (len < r && target > 1) { flag[len][l - 1] = true; target -= 2; n--; len++; } if (target > 2) { // 上擴充套件 flag[r][1] = true; flag[r][2] = true; r++; target -= 3; n -= 2; len = 3; while (len < l && target > 1) { flag[r - 1][len] = true; target -= 2; n--; len++; } } } if (target == 2) { n -= 2; flag[0][1] = true; flag[1][0] = true; } else if (target == 1) { n -= 1; flag[0][1] = true; } print(n); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef ACM_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); int test_index_for_debug = 1; char acm_local_for_debug; while (cin >> acm_local_for_debug) { if (acm_local_for_debug == '$') exit(0); cin.putback(acm_local_for_debug); if (test_index_for_debug > 20) { throw runtime_error("Check the stdin!!!"); } auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } #else solve(); #endif return 0; }