http://ac.jobdu.com/problem.php?id=1333
好久没做过九度上的题目了,今天板子还是调不好,给研究生学长打电话,按他说的弄还是不行。计划明天或者周末亲自去见见他。
显然这个题目是主要要考虑重叠区域,开了一个二维数组,采用标号法,把当前输入矩形所包含的每个1*1的小格进行标记,最后数标记了多少格
还有,小雨啊。。我真的舍不得
#include <stdio.h> #include <stdlib.h> #include <string.h> int mat[102][102]; int n,m,pos[4]; int main() { while(scanf("%d",&n)!=EOF){ int area=0; memset(mat,0,sizeof(mat)); scanf("%d",&m); int i; for(i=1;i<=m;i++){ int j; for(j=0;j<4;j++){ scanf("%d",&pos[j]); if(pos[j]<0) pos[j]=0; else if(pos[j]>100) pos[j]=100; } int p,q; for(p=pos[0]+1;p<=pos[2];p++) for(q=pos[1]+1;q<=pos[3];q++) mat[p][q]=true; } int j; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(mat[i][j]) area++; printf("%d\n",n*n-area); } }