- problem link:http://codeforces.com/contest/1027/problem/B
可以分解开来找规律:看图
以n为4为例,每行有n/2个数。结合坐标特点得出规律。

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

本文解析了CodeForces竞赛中编号为1027的B题,通过观察和分析,找到了解决该问题的规律,并给出了C++实现代码。重点在于如何根据题目中的坐标特性推导出解题公式。

被折叠的 条评论
为什么被折叠?



