题解:P15022 [UOI 2020 II Stage] 邻居
题意过于简单,这里不再累赘
思路
可以发现,对于一个单位格编号为
AC code
#include<bits/stdc++.h>
using namespace std;
int n , k;
signed main(){
cin >> n >> k;
int h = (k - 1) % n + 1;
int l = (k - 1) / n + 1;
if(h == l){
cout << "yes ";
}else{
cout << "no ";
}
if(h + l == n + 1){
cout << "yes ";
}else{
cout << "no";
}
return 0;
}
当然,你可以用第二种方法AC本题。
思路
显而易见,如果这个格子在主对角线上那么格子单位格编号一定:
如果在副对角线上一定:
注:
需注意,当
最后把式子搬进去判断一下即可。
AC code
#include<bits/stdc++.h>
using namespace std;
int n , k;
signed main(){
cin >> n >> k;
if(n == 1 && k == 1){
cout << "yes yes ";
return 0;
}
if((k - 1) % (n + 1) == 0 && (k - 1) / (n + 1) < n){
cout << "yes ";
}else{
cout << "no ";
}
if(k - n >= 0 && (k - n) % (n - 1) == 0 && (k - n) / (n - 1) < n){
cout << "yes ";
}else{
cout << "no ";
}
return 0;
}