思路
观察一下这幅图,你很快就会发现一下规律。
我们设 为圈数。
- 当 时,;否则 。
- 当 时,;否则 。
答案就是连个圈数的最小值再对 取余,公式为:
输入第一个样例后你会发现,它输出:
2
0
1
0显然问题出在 ,应该输出 ,而不是 ,我们特判一下就行了。
Code
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;cin>>n>>k;
while(k--){
int a,b;cin>>a>>b;
int t=min(min(a,n-a+1),min(b,n-b+1));
cout<<(t%3?t%3:3)<<'\n';
}
}