欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Educational Codeforces Round 49 (Rated for Div. 2) B. Numbers on the Chessboard

程序员文章站 2022-06-04 08:13:42
...
  1. problem link:http://codeforces.com/contest/1027/problem/B
  2. 可以分解开来找规律:看图
    Educational Codeforces Round 49 (Rated for Div. 2) B. Numbers on the Chessboard
    以n为4为例,每行有n/2个数。结合坐标特点得出规律。
    Educational Codeforces Round 49 (Rated for Div. 2) B. Numbers on the Chessboard

  3. AC code:

#include<iostream>
using namespace std;
typedef long long ll;
ll n,q,a,b,ans;
int main(){
    cin>>n>>q;
    while(q--){
        cin>>a>>b;
        ans=(a-1)*n+b+1;
        if((a+b)%2)ans+=n*n;
        cout<<ans/2<<endl;
    }
}