傳送門:http://acm.hdu.edu.cn/showproblem.php?pid=3682
題意:
給你一個三維的立方體,每次去掉一列,去掉m列之後問你總共去掉了多少個1*1*1的小立方體。
題解:
用hash來標記每個小立方體,用vector儲存,最後去掉重複的,餘下的即位答案。
AC代碼:
|
3682 |
203MS |
4512K |
2373 B |
G++ |
|
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=33;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-8;vector<int> num;int main(){// freopen("input.txt","r",stdin); int nCase; int n, m; scanf("%d", &nCase); while(nCase--) { num.clear(); int len=0; scanf("%d%d", &n, &m); getchar(); while(m--) { char a, b; int val1, val2; scanf("%c=%d,%c=%d", &a, &val1, &b, &val2); getchar(); if(a=='X') { if(b=='Y') for(int i=1; i<=n; i++) num.push_back(val1*n*n+val2*n+i); else for(int i=1; i<=n; i++) num.push_back(val1*n*n+i*n+val2); } if(a=='Y') { if(b=='X') for(int i=1; i<=n; i++) num.push_back(val2*n*n+val1*n+i); else for(int i=1; i<=n; i++) num.push_back(i*n*n+val1*n+val2); } if(a=='Z') { if(b=='X') for(int i=1; i<=n; i++) num.push_back(val2*n*n+i*n+val1); else for(int i=1; i<=n; i++) num.push_back(i*n*n+val2*n+val1); } } sort(num.begin(), num.end());//排序 num.erase( unique( num.begin(), num.end() ), num.end());//去重 printf("%d\n", num.size()); } return 0;}