UVA 1030 - Image Is Everything【模拟+思维+迭代更新】

题目链接:uva 1030 - Image Is Everything

题目大意:有一个最大为n*n*n的立方体的一个不规整立体,由若干个1*1*1的小正方体构成(每一个小正方体被涂成不同的颜色),给出n,然后是该立体的前、左、后、右、上和下的视图,然后判断该立体的最大体积是多少。

解题思路:首先先把所有视图上为‘.‘的地方清空,然后枚举视图上不为’.‘的地方,计算对应的坐标第一个不为空得位置,将其涂色(注意,若一个正方体被着两种不同的颜色,说明该位置不存在正方体)。

下面给出AC代码:

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const int maxn=10;
  4 int n;
  5 char pos[maxn][maxn][maxn];
  6 char view[6][maxn][maxn];
  7 char read_char()
  8 {
  9     char ch;
 10     for(;;)
 11     {
 12         ch=getchar();
 13         if((ch>=‘A‘&&ch<=‘Z‘)||ch==‘.‘)
 14             return ch;
 15     }
 16 }
 17 void get(int k,int i,int j,int len,int &x,int &y,int &z)
 18 {
 19     if(k==0)
 20     {
 21         x=len;
 22         y=j;
 23         z=i;
 24     }
 25     if(k==1)
 26     {
 27         x=n-1-j;
 28         y=len;
 29         z=i;
 30     }
 31     if(k==2)
 32     {
 33         x=n-1-len;
 34         y=n-1-j;
 35         z=i;
 36     }
 37     if(k==3)
 38     {
 39         x=j;
 40         y=n-1-len;
 41         z=i;
 42     }
 43     if(k==4)
 44     {
 45         x=n-1-i;
 46         y=j;
 47         z=len;
 48     }
 49     if(k==5)
 50     {
 51         x=i;
 52         y=j;
 53         z=n-1-len;
 54     }
 55 }
 56 int main()
 57 {
 58     while(scanf("%d",&n)!=EOF)
 59     {
 60         if(n==0)
 61             break;
 62         for(int i=0;i<n;i++)
 63         {
 64             for(int k=0;k<6;k++)
 65             {
 66                 for(int j=0;j<n;j++)
 67                 {
 68                     view[k][i][j]=read_char();
 69                 }
 70             }
 71         }
 72         for(int i=0;i<n;i++)
 73         {
 74             for(int j=0;j<n;j++)
 75             {
 76                 for(int k=0;k<n;k++)
 77                 {
 78                     pos[i][j][k]=‘#‘;
 79                 }
 80             }
 81         }
 82         for(int k=0;k<6;k++)
 83         {
 84             for(int i=0;i<n;i++)
 85             {
 86                 for(int j=0;j<n;j++)
 87                 {
 88                     if(view[k][i][j]==‘.‘)
 89                     {
 90                         for(int p=0;p<n;p++)
 91                         {
 92                             int x,y,z;
 93                             get(k,i,j,p,x,y,z);
 94                             pos[x][y][z]=‘.‘;
 95                         }
 96                     }
 97                 }
 98             }
 99         }
100         for(;;)
101         {
102             bool done=true;
103             for(int k=0;k<6;k++)
104             {
105                 for(int i=0;i<n;i++)
106                 {
107                     for(int j=0;j<n;j++)
108                     {
109                         if(view[k][i][j]!=‘.‘)
110                         {
111                             for(int p=0;p<n;p++)
112                             {
113                                 int x,y,z;
114                                 get(k,i,j,p,x,y,z);
115                                 if(pos[x][y][z]==‘.‘)
116                                     continue;
117                                 if(pos[x][y][z]==‘#‘)
118                                 {
119                                     pos[x][y][z]=view[k][i][j];
120                                     break;
121                                 }
122                                 if(pos[x][y][z]==view[k][i][j])
123                                     break;
124                                 pos[x][y][z]=‘.‘;
125                                 done=false;
126                             }
127                         }
128                     }
129                 }
130             }
131             if(done)
132                 break;
133         }
134         int ans=0;
135         for(int i=0;i<n;i++)
136         {
137             for(int j=0;j<n;j++)
138             {
139                 for(int k=0;k<n;k++)
140                 {
141                     if(pos[i][j][k]!=‘.‘)
142                         ans++;
143                 }
144             }
145         }
146         printf("Maximum weight: %d gram(s)\n",ans);
147     }
148     return 0;
149 }
时间: 2024-08-01 21:44:23

UVA 1030 - Image Is Everything【模拟+思维+迭代更新】的相关文章

UVA 10881 - Piotr&#39;s Ants【模拟+思维】

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1822 题意:有很多只蚂蚁在一条直线上,每个蚂蚁移动速度都是1,并且有一个初始方向.并且当相邻两个蚂蚁相撞时转向.现在问t时间后各个蚂蚁的位置. 解法:这题的一个致命技巧就是把两只蚂蚁的相撞看作是两只蚂蚁交换穿过对方并且交换蚂蚁的编号.这个是很好理解的,类似于物理的完全弹性碰撞.又由

uva 1030 Image Is Everything(迭代更新)

uva 1030 Image Is Everything Your new company is building a robot that can hold small lightweight objects. The robot will have the intelligence to determine if an object is light enough to hold. It does this by taking pictures of the object from the

UVA 10142 Australian Voting(模拟)

题意:澳大利亚投票系统要求选民们将所有候选人按愿意选择的程度排序,一张选票就是一个排序.一开始,每张选票的首选项将被统计.若有候选人得票超过50%,他讲直接胜出:否则,所有并列最低的候选人出局,而那些将出局候选人排在第一位的选票将被重新统计为排名最高的未出局候选人.这一筛选过程将持续进行,直到某个候选人得到超过50%的选票,或所有候选人得票相同. #include<cstdio> #include<cstring> #include<iostream> #include

模拟+思维 HDOJ 5319 Painter

题目传送门 1 /* 2 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 3 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最小的,脑洞大 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 c

版本更新之模拟数据下载更新

在tomact服务器中自定义web服务,模拟数据下载更新 1.开启tomcat 目录apache-tomcat-7.0.68\bin\startup.bat 2.将apache-tomcat-7.0.68\webapps目录下的WEB-INF拷贝到自定义的目录中,这样就可以访问自定义内容 如:拷贝到apache-tomcat-7.0.68\myApp目录,就可以在浏览器中访问该目录下的text.txt文件 text.txt中写自定义数据: 如  版本2.0 3.开启网络下载数据, 注意:最好使用

MySQL、MongoDB、Redis 数据库之间的区别与使用(本章迭代更新)

MySQL.MongoDB.Redis 数据库之间的区别与使用 MySQL.MongoDB.Redis 数据库之间的区别与使用(本章迭代更新) update:2019年2月20日 15:21:19(本章迭代更新) 一.数据库之间的区别 MySQL MySQL概述 关系型数据库.无论数据还是索引都存放在硬盘中.到要使用的时候才交换到内存中.能够处理远超过内存总量的数据. 在不同的引擎上有不同 的存储方式. 查询语句是使用传统的 SQL 语句,拥有较为成熟的体系,成熟度很高. 开源数据库的份额在不断

UVA - 10023 - Square root (模拟手算开方)

题目传送:UVA - 10023 思路:模拟手算开方,不想用c/c++,感觉太麻烦了,就直接用的java里的BigInteger类来写的,写了好久......Java还是得看看书呀,手算开方参考的这里 AC代码: import java.util.Scanner; import java.math.BigInteger; public class Main { static void fun(BigInteger x) { String str; str = x.toString(); str

UVA 10160 Servicing Stations(状态压缩+迭代加深)

[题目链接] LInk [题目大意] 给出一些点和边,选择一个点就能把这个点和相邻的点都覆盖,求最小点覆盖 [题解] 我们压缩点被覆盖的状态,迭代加深搜索覆盖的最小点数, 当剩余的点全部选上时都无法完全覆盖就剪枝. [代码] #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; const int N=36; int i,n,m,x,y,limit; LL st[N],Lf

UVA - 133 The Dole Queue(模拟链表)

点击打开链接 n的人围成一个环,然后按逆时针编号1-n,一个人从1开始逆时针数k个数,另一个人从N开始顺时针数m个数,然后 数出来的两个人出列(两个人可能一样)出列,然后继续此过程,直到全部人都出列为止. 思路是用循环链表来模拟,注意 要分情况来讨论. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #inclu