Codeforces Round #514 (Div. 2)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37275680/article/details/82948937

A了两道题,第三题没看懂,第五题没看完,第四题还没来得及看。 

Codeforces Round #514 (Div. 2)

A. Cashier 

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
	int n,L,a,pre=0,t,l;
	int cnt=0;
	scanf("%d%d%d",&n,&L,&a);
	while(n--){
		scanf("%d%d",&t,&l);
		cnt+=(t-pre)/a;
		pre=t+l;
	}
	cnt+=(L-pre)/a;
	printf("%d\n",cnt);
	return 0;
} 

B. Forgery 

姑且就把这题理解成盖印章,问印章能否印出下面的图案?枚举中心点,判断其合理性。合理的话给八个方向的'#'做上标记,说明能够盖出这8个'#'。最后枚举所有的'#',看这些’#‘是否都能盖出。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int maxn=1010;
char mp[maxn][maxn];
bool flag[maxn][maxn];
int dir[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
int n,m;

bool check(int x,int y){      //枚举可能是中心点的点,判断这个点是中心点是否合理
	for(int i=0;i<8;i++){
		int fx=x+dir[i][0],fy=y+dir[i][1];
		if(mp[fx][fy]=='.') return false;
	}
	return true;
}

void change(int x,int y){   //合理的话,修改周边'#'的标记,说明这个'#'能被写出
	for(int i=0;i<8;i++){
		int fx=x+dir[i][0],fy=y+dir[i][1];
		flag[fx][fy]=true;
	}
}

bool work(){   //枚举所有点,如果有'#'没被写出,说明这个图形不合法,不能伪造出来
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(mp[i][j]=='#'&&!flag[i][j]) return false;
		}
	}
	return true;
}


int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",mp[i]);
	memset(flag,0,sizeof(flag));
	
	for(int i=1;i<n-1;i++){
		for(int j=1;j<m-1;j++){
			if(check(i,j)) change(i,j);
		}
	}
	
	if(work()) puts("YES");
	else puts("NO");
	return 0;
} 

 C. Sequence Transformation

D. Nature Reserve 

 E. Split the Tree

猜你喜欢

转载自blog.csdn.net/qq_37275680/article/details/82948937