UVA 1030 Image is everything (iterative update)

Source: Internet
Author: User

UVA 1030 Image is everything


Your New company is building a robot so can hold small lightweight objects. The robot'll has the intelligence to determine if a object is light enough to hold. It does the taking pictures of the object from the 6 cardinal directions, and then inferring a upper limit on the obj ECT ' s weight based on those images. You must write a program to do this for the robot.

You can assume this each object is formed from an nxnxn lattice of cubes, some of whic h may be missing. Each1x1x1 cube weighs 1 gram, and each of the cube is painted a single solid color. The object is not necessarily connected.

InputThe input for this problem consists of several test cases representing different objects. Every case begins with a line containing N, which is the size of the object (1 N). The next NLines is the different nx n Views of the "object" in the "Order Front", "left", "back", right, top, bottom. Each view is separated by a single space from the view that follows it. The bottom edge of the top view corresponds to the top edge of the front view. Similarly, the top edge of the bottom view corresponds to the bottom edge of the front view. In each view, colors is represented by single, the unique capital letters, and while a period (.Indicates that the object can is seen through at the.

Input for the last Test case was followed by a line consisting of the number 0.

OutputFor each test case, print a line containing the maximum possible weight of the object, using the format shown below.Sample Input
3.R. Yyr. Y. Ryy. Y.. R.GRB ygr BYG rby gyb GRB. R. Yrr. Y. Rry. R.. Y.2ZZ ZZ ZZ ZZ ZZ ZZZZ ZZ ZZ ZZ ZZ ZZ0
Sample Output
Maximum weight:11 Gram (s) Maximum weight:8 gram (s)



The main idea: there is a cube of the largest n*n*n of a non-regular three-dimensional, by a number of 1*1*1 small cubes (each small cube is painted in different colors), give n, and then the three-dimensional front, left, back, right, upper and lower views, and then determine the maximum volume of the stereo is how much.

The idea of solving problems: first put all views as '. ' The place is emptied, and then the enum view is not '. ' Place, calculate the corresponding coordinates the first is not empty position, paint it (note that if a cube is two different colors, indicating that the position does not exist in the cube), see note.


#include <stdio.h> #include <string.h> #define REP (i,n) for (int i = 0; I < (n); i++)//macros define loops, simplify code int N;cha  R Img[15][15][15], Pos[15][15][15];char getch () {char ch;  while (true) {ch = GetChar ();  if (ch >= ' A ' && ch <= ' Z ') | | ch = = '. ') return ch; }} void get (int i, int j, int k, int m, int& x, int& y, int& z) {//In the K view, I row J column depth is m of the unit cube, coordinates in the original cube (x, Y, Z  ) switch (k) {Case 0:x = i, y = j, z = m; return; Case 1:x = i, y = m, z = n-j-1;  Return Case 2:x = i, y = n-j-1, z = n-m-1;  Return Case 3:x = i, y = n-m-1, z = j;  Return Case 4:x = m, y = j, z = n-i-1;  Return Case 5:x = n-m-1, y = j, z = i; return;}}  int main () {while (scanf ("%d\n", &n) = = 1, N) {Rep (i, N) Rep (K, 6) Rep (j, n) img[k][i][j] = Getch ();  Rep (x, N) Rep (y, N) rep (z, n) pos[x][y][z] = ' * '; int x, y, Z; Rep (K, 6) Rep (i, N) Rep (j, N)//can "see through" the location, the unit block must not exist if (img[k][i][j] = = '. ') {REP (M, n) {get (I, J, K, M, X, Y, z);p os[x][y][z] = '. ';}} WHile (true) {int flag = 1; Rep (K, 6) Rep (i, N) Rep (j, N) if (img[k][i][j]! = '. ') {REP (p, N) {get (I, J, K, p, x, Y, z), if (pos[x][y][z] = = '. ') continue;if (pos[x][y][z] = = ' * ') {pos[x][y][z] = img[k][i][   J];        To "color" the box}if (pos[x][y][z] = = Img[k][i][j]) break;pos[x][y][z] = '. '; If a unit block has a different color, the block does not exist flag = 0;}} if (flag) break;} int sum = 0; Rep (x, N) Rep (y, N) rep (z, N)//statistics Unit number of blocks if (pos[x][y][z]! = '. ') sum++;p rintf ("Maximum Weight:%d gram (s) \ n", sum);} return 0;}




UVA 1030 Image is everything (iterative update)

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.