欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 洛谷P1789

洛谷P1789

2025/2/5 11:54:28 来源:https://blog.csdn.net/2402_88149600/article/details/145243795  浏览:    关键词:洛谷P1789

【Mc生存】插火把 - 洛谷

代码区:

#include<stdio.h>
struct  TORCH{//火把int x,y;
};
struct FLUORITE{//萤石int x,y;
};
int main(){int n,m,k;scanf("%d%d%d",&n,&m,&k);int arry[n][n];for(int i=0;i<n;i++){for(int j=0;j<n;j++){arry[i][j]=0;//0表示无光}}struct TORCH torch[m];struct FLUORITE flu[k];for(int i=0;i<m;i++){scanf("%d%d",&torch[i].x,&torch[i].y);}for(int i=0;i<k;i++){scanf("%d%d",&flu[i].x,&flu[i].y);}//对火把的照亮范围进行处理for(int i=0;i<m;i++){//对斜对角四个方位处理if(torch[i].x-2>=0&&torch[i].y-2>=0)//左上arry[torch[i].x-2][torch[i].y-2]=1;if(torch[i].x&&torch[i].y-2>=0)//左下arry[torch[i].x][torch[i].y-2]=1;if(torch[i].x-2>=0&&torch[i].y)//右上arry[torch[i].x-2][torch[i].y]=1;if(torch[i].x&&torch[i].y)//右下arry[torch[i].x][torch[i].y]=1;//处理行for(int j=torch[i].x-3;j<=torch[i].x+1;j++){if(j>=0&&j<n&&torch[i].y-1>=0){arry[j][torch[i].y-1]=1;}}//处理列for(int j=torch[i].y-3;j<=torch[i].y+1;j++){if(j>=0&&j<n&&torch[i].x-1>=0){arry[torch[i].x-1][j]=1;}}}for(int i=0;i<k;i++){int tempx=flu[i].x-1,countx=0,tempy=flu[i].y-1,county=0;while(tempx>=0&&countx<=2){flu[i].x=tempx;tempx--;countx++;}while(tempy<n&&county<=2){flu[i].y=tempy;tempy++;county++;}for(int j=flu[i].x;j<=flu[i].y;j++){for(int h=flu[i].x;h<=flu[i].y;h++){arry[j][h]=1;}}}int ans=0;for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(arry[i][j]==0){ans++;}}}printf("%d",ans);return 0;
}

欢迎各位读者提出意见。

(菜菜洛谷奋斗小日记)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com