题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=3682
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s):
2724 Accepted Submission(s):
777
#include <iostream> #include <algorithm> #include <stdlib.h> #include <stack> #include <iostream> #include <stdio.h> #include <string> #include <string.h> #include <algorithm> #include <stdlib.h> #include <vector> #include <set> #include <math.h> #include <cmath> #include <map> #include <stack> #include <queue> using namespace std ; typedef long long LL; set<int>myset; set<int>::iterator it; const int Max_N =1001; LL num[Max_N * Max_N]; int main() { int t,n,m; char a,b; int va,vb; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int len=0; for(int i=0 ; i<m ;i++) { getchar(); scanf("%c=%d,%c=%d",&a,&va,&b,&vb); if(a==‘X‘) { if(b==‘Y‘) for(int j=1 ;j <=n ;j++) num[len++]= (va*n*n +vb*n + j ); else for(int j=1 ;j <=n ;j++) num[len++]= (va*n*n +j*n + vb ); } else if(a==‘Y‘) { if(b==‘X‘) for(int j=1 ;j <=n ;j++) num[len++]= (vb*n*n +va*n + j ); else for(int j=1 ;j <=n ;j++) num[len++]= (j*n*n +va*n + vb ); } else { if(b==‘X‘) for(int j=1 ;j <=n ;j++) num[len++]= (vb*n*n +j*n + va ); else for(int j=1 ;j <=n ;j++) num[len++]= (j*n*n +vb*n + va ); } } sort(num,num+len); LL sum=1; for(int i=1 ; i< len ; i++) { if(num[i] != num[i-1]) sum++; } printf("%I64d\n",sum); } return 0; }
这种方法下 , 是不能用 set 和 map 除重, 会超时。
hdu 3682 To Be an Dream Architect hash,布布扣,bubuko.com
hdu 3682 To Be an Dream Architect hash
原文:http://www.cnblogs.com/zn505119020/p/3640827.html