(算法练习)——201403-2窗口(CCF模拟)

这一题用的三维数组hash表,但这一题坑的是一个窗口点击之后,它就成了第一层,原来的第1成了第2,依次类推,所以我是用一个临时temp数组去存每一位的层数,保证从N-1的层号,按第一层、第二层依次放置。

一开始hhash[temp[linshi]][x][y] == true 这个判断条件写成了hhash[linshi][x][y] == true,这是错的,因为最后temp数组里存放的才是层号,linshi不过是个递减的变量罢了,导致前几次提交只有40分,真坑啊= =(考试估计发现不了这个错误,因为测试样例也是对的。。。)
AC代码:

#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

bool hhash[11][3000][3000];

int main(){
	for(int i = 1;i <=10;i++){
		for(int j = 0;j <=2600;j++){
			for(int p = 0; p<=1500;p++){
				hhash[i][j][p] = false;
			}
		}
	}
	int N,M;
	int ans[15];
	int x1,y1,x2,y2,x,y;
	scanf("%d %d",&N,&M);
	for(int i = 0;i < M;i++){   //初始化结果数组 
		ans[i] = -1;
	}
	for(int i = 1;i <=N;i++){
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		for(int j = x1;j <= x2;j++){
			for(int p = y1;p <= y2;p++){
				hhash[i][j][p] = true;
			}
		} 
	}
	int temp[12];
	for(int i = 1;i <=N;i++){   //一个临时的数组 
		temp[i] = i;
	}
	
	for(int a = 0;a <M;a++){
		scanf("%d %d",&x,&y);
		int linshi = N;
		int signal = 1;
		while(signal>0 && linshi>= 1){
			if(hhash[temp[linshi]][x][y] == true){    //是temp[linshi]中存放的层数使它成功,而不是hhash[linshi][x][y],注意!! 
				ans[a] = temp[linshi];
				for(int s = linshi;s <N;s++){     //点击之后这一层就变为第一层,要用数组换序 
					temp[s] = temp[s+1];
				}
				temp[N] = ans[a];
				signal = -1;	//找到一个不再继续找 
			}
			else{
				linshi--;
			}
		}
	}
	for(int i = 0;i <M;i++){
		if(ans[i] == -1){
			printf("IGNORED\n");
		}
		else{
			printf("%d\n",ans[i]);
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值