http://acm.xidian.edu.cn/problem.php?id=1155
先确定在往里数的第几个圈上,然后根据位置确定数字。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; long long k,x,y,ans; int main() { while(~scanf("%lld%lld%lld",&k,&x,&y)) { long long p = min(x,y); p = min(p,k-x+1); p = min(p,k-y+1); long long dis = x-p+y-p; if(x <= y) ans = 4*(p-1)*(k-p+1)+1+dis; else ans = 4*p*(k-p)+1-dis; printf("%lld\n",ans); } return 0; }
时间: 2024-10-27 12:00:14