2020牛客暑期多校训练营(第三场)D——Points Construction Problem
@[TOC](2020牛客暑期多校训练营(第三场)D——Points Construction Problem)
题目描述
输入描述
The first line contains one integer t (1≤t≤10 3) — the number of test cases.
The only line of each test case contains two integers n and m (1≤n≤50,1≤m≤200).
输出描述
For each test, if there exists at least one configuration to choose n points to satisfy the conditions given by statement, you should print n+1 line for this test. The first line contains one string “Yes”. And the following n lines contain the coordinator of these n points which is colored as black. If there are no solution, please print one line containing only one string “No”.
输入
6 5 20 1 2 1 3 1 4 1 5 3 8
输出
Yes 1 1 2 2 3 3 4 4 5 5 No No Yes 1 1 No Yes 1 1 1 2 2 1
说明
In the first test and fourth test, each black point in the sample output is adjacent to exactly 4 white points.
In the sixth test, the second and third black points in the sample output are both adjacent to 3 white points and the forst black point is adjacent to 2 white points.
题目大意
假设您有一个具有笛卡尔坐标系的无限二维平面。 最初,所有整数点(xy坐标都为整数的点)都绘制为白色。 给出两个整数n和m。 请精确地将n个整数点涂成黑色,使得刚好有m个点对满足以下条件:
1.这两点用不同的颜色着色。
2.这两点相邻。 我们称两个整数点(x1,y1)和(x2,y2)相邻,当且仅当∣x1-x2∣ + ∣y1 −y2∣ = 1。 (| v |表示v的绝对值。)
3.所有黑点的x和y坐标在[-10 ^ 9,10 ^ 9] 范围内。
对于每项测试,如果至少存在一个配置来选择n个点来满足语句给出的条件,则应打印此测试的n+1行。第一行包含一个字符串“Yes”。并且下面的n行包含这n个黑色点的坐标。如果没有解决方案,请打印一行,该行仅包含一个字符串“No”。
题解
每个黑格子的贡献只能是4,2,0所以答案只能是偶数。我们可以类比构造来实现本题。
*注:本题有特殊评判机制!
AC代码
#pragma GCC optimize(2) #pragma GCC optimize(3) #include<bits/stdc++.h> #define ll long long using namespace std; ll T,n,m,i,j,k,l,o,p,a[10010][10010]; int main() { //ios::sync_with_stdio(false); for(scanf("%lld",&T);T--;) { scanf("%lld%lld",&n,&m); if(m&1||m>4*n||n*16>m*m) puts("No"); else { puts("Yes"); if (m>2*n+2) { o=(m-(2*n+2))/2;p=n-o; for (i=1;i<=p;i++) printf("1 %lld\n",i); for (i=1;i<=o;i++) printf("4 %lld\n",i*2); } else { o=m/4,p=m/2-o; for(i=1;i<=o;i++) printf("%lld 1\n",i); for(j=2;j<=p;j++) printf("1 %lld\n",j); l=n-(o+p-1); for(i=2;i<=o&&l>0;i++) for(j=2;j<=p&&l>0;j++,l--) printf("%lld %lld\n",i,j); } } } }
- 2020牛客暑期多校训练营(第三场)
- 2020牛客暑期多校训练营(第四场)——Basic Gcd Problem
- 牛客多校暑假训练营2020 (第三场) B-【Classical String Problem】
- 2020牛客暑期多校训练营(第四场)——HHarder Gcd Problem
- 2020牛客暑期多校训练营(第三场)E——Two Matchings
- 2020牛客暑期多校训练营(第六场)
- 2020牛客暑期多校训练营(第八场)
- 2020牛客暑期多校训练营(第四场)
- 2020牛客暑期多校训练营第六场Harmony Pairs(数位dp)
- 2020牛客暑期多校训练营第六场Binary Vector(数学,打表)
- 2020牛客暑期多校训练营(第七场)——I Valuable Forests
- 牛客(多校3):Points Construction Problem
- 2020牛客暑期多校训练营(第五场)——E Bogo Sort
- 2020牛客暑期多校训练营(第五场)
- 2020牛客暑期多校训练营(第二场)
- 2020牛客暑期多校训练营(第二场)C Cover the Tree
- 2020牛客暑期多校训练营(第四场)——I Investigating Legions
- 2020牛客暑期多校训练营(第四场)——AAncient Distance
- 2019牛客暑期多校训练营(第三场) D-Big Integer
- 2020牛客暑期多校训练营(第二场)F.Fake Maxpooling