【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;
}
欢迎各位读者提出意见。
(菜菜洛谷奋斗小日记)