【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)
題干:
You are given a chessboard of size?n×nn×n. It is filled with numbers from?11?to?n2n2?in the following way: the first??n22??n22??numbers from?11?to??n22??n22??are written in the cells with even sum of coordinates from left to right from top to bottom. The rest?n2??n22?n2??n22??numbers from??n22?+1?n22?+1?to?n2n2?are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation??xy??xy??means division?xx?by?yy?rounded up.
For example, the left board on the following picture is the chessboard which is given for?n=4n=4?and the right board is the chessboard which is given for?n=5n=5.
You are given?qq?queries. The?ii-th query is described as a pair?xi,yixi,yi. The answer to the?ii-th query is the number written in the cell?xi,yixi,yi?(xixi?is the row,?yiyi?is the column). Rows and columns are numbered from?11?to?nn.
Input
The first line contains two integers?nn?and?qq?(1≤n≤1091≤n≤109,?1≤q≤1051≤q≤105) — the size of the board and the number of queries.
The next?qq?lines contain two integers each. The?ii-th line contains two integers?xi,yixi,yi(1≤xi,yi≤n1≤xi,yi≤n) — description of the?ii-th query.
Output
For each query from?11?to?qq?print the answer to this query. The answer to the?ii-th query is the number written in the cell?xi,yixi,yi?(xixi?is the row,?yiyi?is the column). Rows and columns are numbered from?11?to?nn. Queries are numbered from?11?to?qq?in order of the input.
Examples
Input
4 5 1 1 4 4 4 3 3 2 2 4Output
1 8 16 13 4Input
5 4 2 1 4 2 3 3 3 4Output
16 9 7 20Note
Answers to the queries from examples are on the board in the picture from the problem statement.
題目大意:
? ? 這題干已經沒法看了,,格式都亂了,但是題意很簡單。給一個n,然后先填x和y坐標和為偶數的,填滿后再填奇數的。給q個詢問,每個詢問x和y坐標,輸出這個坐標的值是多少。
解題報告:
? ?這題是真!MMP! 無聊!!首先看(x+y)是奇數還是偶數,然后xjb找規律,,,真的是無聊這題,,,大概就是先算前(x-1)行的,再看第x行的
AC代碼:
#include<bits/stdc++.h> #define ll long long using namespace std; int main() {ll n,q,x,y;cin>>n>>q;while(q--) {scanf("%lld%lld",&x,&y);ll ans = n*(x-1) + y + 1;if((x+y) % 2 == 1) {ans += n*n;} cout << ans/2 << endl;}return 0 ; }?
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: schedulerv2.exe - sc
- 下一篇: 办信用卡哪个银行好 比较好办的信用卡都在