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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Light2Chasers/article/details/81822322
  1. problem link:http://codeforces.com/contest/1027/problem/B
  2. 可以分解开来找规律:看图
    横纵坐标之和为偶数
    以n为4为例,每行有n/2个数。结合坐标特点得出规律。
    横纵坐标之和为奇数

  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;
    }
}

猜你喜欢

转载自blog.csdn.net/Light2Chasers/article/details/81822322