建设网站500错误,做网站人员配置,宝塔默认安装wordpress,阿里域名注册网站http://acm.hdu.edu.cn/showproblem.php?pid2461 题目很简单#xff0c;但是由于询问数M可以很大#xff0c;所以容易超时#xff0c;这道题学到了在结构体里面写函数的方法#xff0c;这样子效率更高#xff0c;否则的话#xff0c;这道题就TLE了。 根据容斥原理#…http://acm.hdu.edu.cn/showproblem.php?pid2461 题目很简单但是由于询问数M可以很大所以容易超时这道题学到了在结构体里面写函数的方法这样子效率更高否则的话这道题就TLE了。 根据容斥原理先把每个小长方形的面积加上然后看有没有与该小长方形相交的用dfs实现当相交面积为0时则不进行dfs且同样遵循奇加偶减但代码里因为是以第二个作为depth1开始进行dfs的所以是奇减偶加。 AC代码 #includeiostream
#includecstdio
#includealgorithm
#includecmath
using namespace std;struct Node
{int x1,x2,y1,y2;Node cross(Node R){Node tmp;tmp.x1max(x1,R.x1);tmp.y1max(y1,R.y1);tmp.x2min(x2,R.x2);tmp.y2min(y2,R.y2);return tmp;}int area(){if(x1x2||y1y2) return 0;return (x2-x1)*(y2-y1);}
}node[25];int num,r[25],ans;
void dfs(int depth,Node R,int index)
{Node tmp;for(int iindex;inum;i){tmpR.cross(node[r[i]]);if(tmp.area()){if(depth1)ans-tmp.area();else anstmp.area();dfs(depth1,tmp,i1);}}
}int main()
{int n,m,cas0;while(scanf(%d%d,n,m)nm){cas;for(int i1;in;i)scanf(%d%d%d%d,node[i].x1,node[i].y1,node[i].x2,node[i].y2);printf(Case %d:\n,cas);for(int i1;im;i){ans0;scanf(%d,num);for(int j1;jnum;j)scanf(%d,r[j]);for(int j1;jnum;j){ansnode[r[j]].area();dfs(1,node[r[j]],j1);}printf(Query %d: %d\n,i,ans);}printf(\n);}return 0;
}转载于:https://www.cnblogs.com/atmacmer/p/5293586.html