题意不太好理解 求横黑条 和竖黑条共有多少个 注意1*1的情况 如果横向纵向都是1*1 算为一个 否则不算
用了下vector 枚举找下
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 using namespace std; 8 #define N 30010 9 vector<int>p[N]; 10 vector<int>q[N]; 11 int o1[N],o2[N]; 12 int main() 13 { 14 int i,j,m,n,k,x,y,t,sum=0; 15 scanf("%d%d%d",&m,&n,&k); 16 for(i = 1; i <= k ;i++) 17 { 18 scanf("%d%d",&x,&y); 19 p[x].push_back(y); 20 q[y].push_back(x); 21 } 22 for(i = 1; i <= m ; i++) 23 p[i].push_back(n+1); 24 for(i = 1; i <= n ; i++) 25 q[i].push_back(m+1); 26 for(i = 1; i <= m ; i++) 27 { 28 t = 0; 29 sort(p[i].begin(),p[i].end()); 30 for(j = 0; j < (int)p[i].size() ; j++) 31 { 32 if(p[i][j]-t>2) 33 sum+=1; 34 t = p[i][j]; 35 } 36 } 37 for(i = 1; i <= n ; i++) 38 { 39 sort(q[i].begin(),q[i].end()); 40 t = 0; 41 for(j = 0 ; j < (int)q[i].size() ; j++) 42 { 43 if(q[i][j]-t>2) 44 sum+=1; 45 else if(q[i][j]-t>1) 46 { 47 int ot = q[i][j]-1; 48 t = 0; 49 for(int g = 0 ; g < (int)p[ot].size() ; g++) 50 { 51 if(p[ot][g]>i) 52 { 53 if(p[ot][g]-t<=2) 54 sum+=1; 55 break; 56 } 57 t = p[ot][g]; 58 } 59 } 60 t = q[i][j]; 61 } 62 } 63 printf("%d ",sum); 64 return 0; 65 }