Educational Codeforces Round 49 (Rated for Div. 2) B. Numbers on the Chessboard
程序员文章站
2022-06-04 08:13:42
...
- 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;
}
}
推荐阅读
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
Educational Codeforces Round 98 (Rated for Div. 2) A-E 题解
-
Educational Codeforces Round 93 (Rated for Div. 2) A. Bad Triangle
-
Educational Codeforces Round 93 (Rated for Div. 2) B - Substring Removal Game
-
Educational Codeforces Round 99 (Rated for Div. 2) C. Ping-pong
-
第十五次训练:Educational Codeforces Round 72 (Rated for Div. 2) && Codeforces Round #582 (Div. 3)
-
第二次训练:Educational Codeforces Round 77 (Rated for Div. 2)