HDU 3682 To Be an Dream Architect (hash)

來源:互聯網
上載者:User

傳送門: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;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.