Address: HDU 2120
Although this question does not contain many words, it cannot be understood .. It means to find the maximum number of areas surrounded by walls. This is obviously the number of rings. Then, use and query the set to find the number of rings.
The Code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int bin[2000];int find1(int x){ return bin[x]==x?x:bin[x]=find1(bin[x]);}int main(){ int n, m, ans, a, b, f1, f2, i; while(scanf("%d%d",&n,&m)!=EOF) { ans=0; for(i=0;i<n;i++) bin[i]=i; while(m--) { scanf("%d%d",&a,&b); f1=find1(bin[a]); f2=find1(bin[b]); if(f1==f2) ans++; else bin[f2]=f1; } printf("%d\n",ans); } return 0;}
HDU 2120 ice_cream's world I (query set)