Hdu 3682 to is an Dream Architect (Hash)

Source: Internet
Author: User

Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=3682

Idea: Hash. For each (x, y, z) coordinate of the cube, map to X*n*n+y*n+z, determine how many different numbers is to delete the number of cubes.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int n,m;vector<int> ans;inline int Hash (int x,int y,int z) {return x*n*n+y*n+z;}    int main () {int t;    scanf ("%d", &t);        while (t--) {ans.clear ();        scanf ("%d%d", &n,&m);            for (int i=0; i<m; i++) {char ch1,ch2;            int pos1,pos2;            GetChar ();            scanf ("%c=%d,%c=%d", &ch1,&pos1,&ch2,&pos2);                        if (ch1== ' Y ') {if (ch2== ' X ') {for (int z=1; z<=n; z++)                Ans.push_back (Hash (pos2,pos1,z)); } else {for (int x=1; x<=n; x + +) Ans.push_back (                Hash (X,pos1,pos2)); }} else if (ch1== ' X ') {if (ch2== ' Y ') {f or (int z=1;z<=n;                z++) Ans.push_back (Hash (pos1,pos2,z)); } else {for (int y=1; y<=n; y++) Ans.push_back (                Hash (Pos1,y,pos2)); }} else if (ch1== ' Z ') {if (ch2== ' Y ') {f                or (int x=1; x<=n; x + +) Ans.push_back (Hash (X,POS2,POS1)); } else {for (int y=1; y<=n; y++) Ans.push_back (                Hash (POS2,Y,POS1));        }}} sort (Ans.begin (), Ans.end ());        int Num=unique (Ans.begin (), Ans.end ())-ans.begin ();    printf ("%d\n", num); } return 0;}



Hdu 3682 to is an Dream Architect (Hash)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.