2017CCPC final K bfs打表 llu

在这里插入图片描述
在这里插入图片描述unsiged long long 会爆

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const ll mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll n,m;
ll vis[1005][1005];
ll ans[25];
ll dir[8][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
struct node{
	ll x,y,step;
};
void bfs(){
	queue<node> q;
	node tmp;
	tmp.x=500;tmp.y=500;tmp.step=0;
	ans[0]=1;vis[500][500]=1;	//走0步占1个位置
	q.push(tmp);
	while(!q.empty()){
		node p=q.front();
		q.pop();
		if(p.step==20)	
			break;
		for(int i=0;i<8;i++){
			ll xx=p.x+dir[i][0];
			ll yy=p.y+dir[i][1];
			if(vis[xx][yy])
				continue;
			vis[xx][yy]=1;
			node tmp;
			tmp.x=xx;tmp.y=yy;tmp.step=p.step+1;
			ans[tmp.step]++;
			q.push(tmp);
		}
	}
}
int main(){
	bfs();
	ll sum=1;
	for(int i=1;i<=19;i++){
		sum+=ans[i];
		cout<<"sum "<<sum<<" "<<"level "<<ans[i]<<" "<<ans[i]-ans[i-1]<<endl;
	}
	return 0;
}
scanf("%llu",&num);  
        
printf("Case #%d: %llu\n",i,anss);    
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int maxn=1e6+5;
ull ans[8]={1,9,41,109,205,325,473,649};
ull n,res;
int T;
int main(){
	cin>>T;
	for(int i=1;i<=T;i++){
		res=0;
		cin>>n;
		if(n<=6){
			cout<<"Case #"<<i<<": "<<ans[n]<<endl;
			continue;
		}
		res=473;
		ull cnt=n-6;
		res+=cnt*148;
		res+=(cnt+1)*cnt/2*28;
		cout<<"Case #"<<i<<": "<<res<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值