给定 \(n,m\) 要你求出在 \(n*m\) 的棋盘上最多能摆多少个象(国际象棋)。输出方案。
挺无聊的。但是这是我这一个月以来模拟赛中场切的第一题。
先想到一个非常显然的构造:默认 \(n \leq m\)。先放 \(2n\) 个棋子在第一行和第 \(m\) 行,然后中间填个一线天出来。
对了。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
void print(int x, int y, bool fl){
if(fl) swap(x, y);
write(x), put(), write(y), endl;
}
void solve(){
int n = read(), m = read();
bool fl = 0;
if(n > m){
fl = 1;
swap(n, m);
}
if(n == 1){
write(m), endl;
for(int i = 1; i <= m; i++){
print(1, i, fl);
// write(1), put(), write(i), endl;
}
return ;
}
if(n == m){
write(n * 2 - 2), endl;
for(int i = 1; i <= n; i++){
print(1, i, fl);
}
for(int i = 2; i < n; i++){
print(n, i, fl);
}
return ;
}
if(n % 2){
write(2 * n + m - (n + 1)), endl;
for(int i = 1; i <= n; i++){
print(i, 1, fl);
}
for(int i = 1; i <= n; i++){
print(i, m, fl);
}
int mk = (n + 1) / 2;
for(int i = (n + 1) / 2 + 1; i <= (n + 1) / 2 + 1 + (m - n - 1) - 1; i++){
print(mk, i, fl);
}
// return ;
}else{
bool fl2 = 0;
if(m % 2 == 0){
m--;fl2=1;
}
write(2 * n + m - (n + 1)), endl;
for(int i = 1; i <= n; i++){
print(i, 1, fl);
}
for(int i = 1; i <= n; i++){
print(i, m, fl);
}
int mk = n / 2, mk2 = n / 2 + 1;
int cnt = m - (n + 1), now = 2 + n / 2;
while(cnt){
cnt -= 2;
print(mk, now, fl);
print(mk2, now, fl);
now += 2;
}
m += fl2;
}
// if(fl) swap(n, m);
// for(int i = 1; i <= n; i++){
// for(int j = 1; j <= m; j++){
// write(a[i][j]);
// }endl;
// }endl;
}
signed main(){
freopen("bishop.in", "r", stdin);
freopen("bishop.out", "w", stdout);
int t = 1;
while(t--) solve();
return 0;
}