HDU - 6253 Knightmare [打表找规律]

A knight jumps around an infinite chessboard. The chessboard is an unexplored territory. In the spirit of explorers, whoever stands on a square for the first time claims the ownership of this square. The knight initially owns the square he stands, and jumps NN times before he gets bored. 
Recall that a knight can jump in 8 directions. Each direction consists of two squares forward and then one squaure sidways. 


After NN jumps, how many squares can possibly be claimed as territory of the knight? As NN can be really large, this becomes a nightmare to the knight who is not very good at math. Can you help to answer this question?

Input

The first line of the input gives the number of test cases, TT. TT test cases follow. 
Each test case contains only one number NN, indicating how many times the knight jumps. 
1≤T≤1051≤T≤105 
0≤N≤1090≤N≤109

Output

For each test case, output one line containing “Case #x: y”, where xx is the test case number (starting from 1) and yy is the number of squares that can possibly be claimed by the knight.

Sample Input

3
0
1
7

Sample Output

Case #1: 1
Case #2: 9
Case #3: 649

他们数论的做法我看不懂   但打表后发现 6以后每一层的递增量是一个等差数列 公差为28 

还卡了精度 要用long long unsigned

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
/*
int map[1000][1000];
int visit[1000][1000];
int dir[8][2]={-2,-1,-1,-2,1,-2,2,-1,-2,1,-1,2,1,2,2,1};
int ans[1000];
struct node
{
	int step,x,y;
};
int main()
{
	queue<node> q;
	node start,in,ne;
	start.x=500,start.y=500,start.step=0;
	visit[500][500]=1;
	ans[0]=1;
	q.push(start);
	while(!q.empty())
	{
		in=q.front();
		q.pop();
		if(in.step>20) break;
		for(int i=0;i<8;i++)
		{
			ne.y=in.y+dir[i][1];
			ne.x=in.x+dir[i][0];
			ne.step=in.step+1;
			if(!visit[ne.x][ne.y])
			{
				q.push(ne);
				ans[ne.step]++;
				visit[ne.x][ne.y]=1;
			}
		}
	}
	int sum=1,presum;
	for(int i=1;i<=20;i++)
	{
		sum+=ans[i]; 
		cout<<"cishu"<<ans[i]<<'\t'<<"sum"<<sum<<"cha"<<ans[i]-ans[i-1]<<endl;
		presum=sum;
	}
}*/
int main()
{
	int ans[8]={1,9,41,109,205,325,473,649};
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		unsigned long long num;
		scanf("%llu",&num);
		if(num<=6)
		{
			printf("Case #%d: %d\n",i,ans[num]);
		}
		else
		{
			unsigned long long base=473,s=num-6,ss;
			base+=148*s;
			ss=((1+s)*s)/2;
			base+=28*ss;
			printf("Case #%d: %llu\n",i,base);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值