2015百度之星资格赛系列

// 2015百度之星资格赛系列
//
// 首先,1001这道题,挺简单,分成这个数单独一组(i) 或者与某本书一组(i,j)
// 则在第n项后面再添加一本书,那么这本书单着的情况就是f(n),与前面n个里面
// 的任意一项组成一组,则是f(n-1),那么公式就出来了
//
// 1002 水题,从第一个开始取设为x,每次加上k,最后超出length的时候让x对k取膜
// 加1的结果再送x,直到取完所有,即为答案
//
// 1003 水题,其实这一题可以在每个子网掩码下,直接算出ip,最后用二重循环爆出
// 相同的,把相同的某一项置为负数或者比255大的数,最后找出来就可以了
//
// 1004 经典博弈,满足第一次可以放盘子,先手必胜,否则必败,算出中心到边的
// 距离与r比较即可
//
// 1005 其实也是个水题,预处理出骑士和国王从各自的起点出发,到达每个点的最短时间
// 则对于国王来说,如果能在i秒的时候到达该点,则i+1,i+2...k都可以到达该点
// 对于骑士而言,如果在第j秒的时候到达该点,则j+2,j+4...(even)(k,k-1)都可以到达该点
// 最后,只要根据这两个时间分类讨论即可
// 如果国王先到该点,而骑士后到,则时间就是骑士的时间
// 反之骑士先到,国王后到,则时间就是国王的时间+((骑士与国王同奇偶)? 0: 1);
//
// 1006 概率d问题,这个真不会,,等有功夫再仔细想想吧
//
// 最后对于这次资格赛的感受,总体上还是比较简单
// 就是在1005上,一开始看错了题目,以为国王是只能走四个方向,一直按照国王
// 也是奇数或者偶数的情况写,结果一直跪了4个多小时,贴个1005的代码,哎,继续练吧,还是做题目少了
//
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ceil(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define gcd __gcd
#define highBit(x) (1ULL<<(63-__builtin_clzll(x)))
#define popCount __builtin_popcountll
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const long double PI = acos(-1.L);

template<class T> inline T lcm(const T& a, const T& b) { return a/gcd(a, b)*b; }
template<class T> inline T lowBit(const T& x) { return x&-x; }
template<class T> inline T maximize(T& a, const T& b) { return a=a<b?b:a; }
template<class T> inline T minimize(T& a, const T& b) { return a=a<b?a:b; }

const int maxn = 1008;
int v[maxn][maxn];
const int inf = 0x6f6f6f6f;
int kix,kiy,knx,kny;
int n,m,k;

bool vis2[maxn][maxn];
int a[maxn][maxn];
int b[maxn][maxn];

struct node{
	int x;
	int y;
	int t;
	node(int x,int y,int t):x(x),y(y),t(t){

	}
};

const int ndx[8] = {-2,-1,1,2,2,1,-1,-2};
const int ndy[8] = {1,2,2,1,-1,-2,-2,-1};

void init(){
	cin >> n >> m >> k;
	cin >> kix >> kiy;
	cin >> knx >> kny;
	memset(vis2,0,sizeof(vis2));
	memset(a,0,sizeof(a));
	memset(b,inf,sizeof(b));
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			a[i][j] = max(a[i][j],max(abs(i-kix),abs(j-kiy)));
		}
	a[kix][kiy] = 2;
//	for (int i=1;i<=n;i++){
//		for (int j=1;j<=m;j++){
//			cout << a[i][j] << " ";
//		}
//		cout << endl;
//	}
//	cout << endl;
}



int cnt ;

bool ok(int x,int y){
	if (x>=1&&x<=n&&y>=1&&y<=m)
		return true;
	return false;
}


void bfs2(){
	queue<node> que;
	que.push(node(knx,kny,0));
	vis2[knx][kny] = 1;
	while(!que.empty()){
		node x = que.front();
		if (x.t>=k)
			break;
		que.pop();
		for (int i=0;i<8;i++){
			int tx = x.x + ndx[i];
			int ty = x.y + ndy[i];
			if (!ok(tx,ty))
				continue;

			if (!vis2[tx][ty]){
				vis2[tx][ty] = 1;
				b[tx][ty] = min(b[tx][ty],x.t+1);
				que.push(node(tx,ty,x.t+1));
			}
		}
	}
	b[knx][kny] = 2;
//	for (int i=1;i<=n;i++){
//		for (int j=1;j<=m;j++){
//			cout << b[i][j] << " ";
//		}
//		cout << endl;
//	}
}
void solve(){
	if (abs(kix-knx)>3 * k || abs(kiy-kny) > 3 * k){
		puts("OH,NO!");
		return ;
	}
	bfs2();
	cnt = inf;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			if (a[i][j]>0 && b[i][j]<inf){
				int le1 = a[i][j];
				int le2 = b[i][j];
				int temp;
				if (le1<le2)
					temp = le2;
				else if (((le1-le2)&1)==1){
					temp = le1 + 1;
				}else {
					temp = le1 ;
				}
				//cout << "temp = " << temp << endl;
				cnt = min(temp,cnt);
			}
		}
	if (cnt>k){
		puts("OH,NO!");
	}
	else {
		printf("%d\n",cnt);
	}
}

int main() {
	int t;
	//freopen("G:\\Code\\1.txt","r",stdin);
	scanf("%d",&t);
	int kase = 1;
	while(t--){
		printf("Case #%d:\n",kase++);
		init();
		solve();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值