题解:P9355 「SiR-1」Checkmate

· · 题解

解题思路

对于每一对相邻格子,先放置的棋子得分加 1,后放置的棋子不加分。

因此得分总和等于相邻格子的对数,具体计算如下:

因此,相邻格子的总对数为:

n(m-1)+m(n-1)=2nm-n-m

参考代码

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--)
    {
        ll n,m;
        cin>>n>>m;
        cout<<n*m*2-n-m<<'\n';
    }
    return 0;
}