洛谷-P1789 【Mc生存】插火把

题目背景

初一党应该都知道......

题目描述

话说有一天 linyorson 在“我的世界”开了一个 n\times n(n\le 100)n×n(n≤100) 的方阵,现在他有 mm 个火把和 kk 个萤石,分别放在 (x_1,y_1)...(x_m,y_m)(x1​,y1​)...(xm​,ym​) 和 (o_1,p_1)...(o_k,p_k)(o1​,p1​)...(ok​,pk​) 的位置,没有光或没放东西的地方会生成怪物。请问在这个方阵中有几个点会生成怪物?

P.S.火把的照亮范围是:

    |暗|暗| 光 |暗|暗|
    |暗|光| 光 |光|暗|
    |光|光|火把|光|光|
    |暗|光| 光 |光|暗|
    |暗|暗| 光 |暗|暗|

萤石:

    |光|光| 光 |光|光|
    |光|光| 光 |光|光|
    |光|光|萤石|光|光|
    |光|光| 光 |光|光|
    |光|光| 光 |光|光|

输入格式

输入共m+k+1行。

第一行为n,m,k。

第2到第m+1行分别是火把的位置xi yi。

第m+2到第m+k+1行分别是萤石的位置oi pi。

注:可能没有萤石,但一定有火把。

所有数据保证在int范围内。

输出格式

有几个点会生出怪物。

输入输出样例

输入 #1复制

5 1 0
3 3

输出 #1复制

12
#include<bits/stdc++.h>
using namespace std;
const int size=103;
int a[size][size];
	int n,m,k;
	int x,y;

//若果是萤石t=2,是火把t=1 
void light(int x,int y,int t){
	for(int i=x-t;i<=x+t;i++){
		for(int j=y-t;j<=y+t;j++){
			if(i>n||i<1||j>n||j<1){
				continue;
			}else{
				a[i][j]=1;
			}
		}
	} 
}

void ys(int x,int y){
	light(x,y,2);
}

void hb(int x,int y){
	light(x,y,1);
	if(x+2<=n){
		a[x+2][y]=1;
	}
	if(x-2>0){
		a[x-2][y]=1;
	}
	if(y+2<=n){
		a[x][y+2]=1;
	}
	if(y-2>0){
		a[x][y-2]=1;
	}
}


int main(){

	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		hb(x,y);
	}
	for(int i=1;i<=k;i++){
		cin>>x>>y;
		ys(x,y);
	}
	
	
	int count=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]==0){
				count++;
			}
		}
	}
	cout<<count;
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41877184/article/details/103033437