Uva LV 2995 Image Is Everything 模拟,坐标映射,视图映射 难度: 1

题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996

题意

被射击掉了一些列的魔方。组成模仿的每个方块的六个面颜色相同。给六个面的视图,求魔方最多还剩下多少个小块。

魔方最多十阶。

思路

关键在于将视图的坐标(加上视图深度)映射为三维坐标系内的坐标,之后就可以不断删除会造成矛盾的暴露在表面的方块,直到没有方块或者没有矛盾为止。

感想

1. 注意<写成了>=

2. 忘记了检测当前方块是否已经删除过了。

3. 忘了memset

4. 视图的映射有价值,不过需要注意坐标系建立不同

代码

Runtime: 0.006

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <cassert>

using namespace std;
#define LOCAL_DEBUG
const int MAXN = 11;

int n;
bool del[MAXN][MAXN][MAXN];
char color[MAXN][MAXN][MAXN];
char fc[6][MAXN][MAXN];
int deep[6][MAXN][MAXN];
int facec[3];
int polarc[3];

char statusDescribe[6][4] = {
    "YXZ",
    "ZXy",
    "yXz",
    "zXY",
    "YZx",
    "YzX"
};

int getAns() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (!del[i][j][k])ans++;
            }
        }
    }
    return ans;
}

void face2polar(int fid, int facec[3], int polarc[3]) {
    for (int i = 0; i < 3; i++) {
        char sta = statusDescribe[fid][i];
        if (sta >= ‘X‘ && sta <= ‘Z‘) {
            polarc[i] = facec[sta - ‘X‘];
        }
        else {
            polarc[i] = n - 1 - facec[sta - ‘x‘];
        }
    }
}

void polar2face(int fid, int facec[3], int polarc[3]) {
    for (int i = 0; i < 3; i++) {
        char sta = statusDescribe[fid][i];
        if (sta >= ‘X‘ && sta <= ‘Z‘) {
            facec[sta - ‘X‘] = polarc[i];
        }
        else {
            facec[sta - ‘x‘] = n - 1 - polarc[i];
        }
    }
}

int main() {
#ifdef LOCAL_DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output2.txt", "w", stdout);
#endif // LOCAL_DEBUG
    for (int ti = 1; scanf("%d", &n) == 1 && n; ti++) {
        memset(del, 0, sizeof(del));
        memset(color, 0, sizeof(color));
        memset(fc, 0, sizeof(fc));
        memset(deep, 0, sizeof(deep));
        memset(facec, 0, sizeof(facec));
        memset(polarc, 0, sizeof(polarc));
        char buff[100];
        cin.getline(buff, 100);
        for(int i = 0; i < n;i++){
            cin.getline(buff, 100);
            for (int k = 0; k < 6; k++) {
                for (int j = 0; j < n; j++) {
                    fc[k][i][j] = buff[(n + 1) * k + j];
                }
            }
        }

        int &x = facec[0];
        int &y = facec[1];
        int &z = facec[2];
        int &a = polarc[0];
        int &b = polarc[1];
        int &c = polarc[2];
        for (int fid = 0; fid < 6; fid++) {
            for (x = 0; x < n; x++) {
                for (y = 0; y < n; y++) {
                    if (fc[fid][x][y] == ‘.‘) {
                        deep[fid][x][y] = n;
                        for (z = 0; z < n; z++) {
                            face2polar(fid, facec, polarc);
                        //    printf("R: %d, del %d-(%d, %d, %d) : (%d, %d, %d)\n", getAns(), fid, x, y, z, a, b, c);
                            del[a][b][c] = true;
                        }
                    }
                }
            }
        }
        bool checkFlag = true;
        while (checkFlag) {
            checkFlag = false;
            for (int fid = 0; fid < 6; fid++) {
                for (x = 0; x < n; x++) {
                    for (y = 0; y < n; y++) {
                        for (z = deep[fid][x][y]; z < n; z++, deep[fid][x][y]++) {
                            face2polar(fid, facec, polarc);
                            if (del[a][b][c])continue;
                            else if (color[a][b][c] == 0 || color[a][b][c] == fc[fid][x][y]) {
                                color[a][b][c] = fc[fid][x][y];
                                break;
                            }
                            else{
                                del[a][b][c] = true;
                                checkFlag = true;
                            }
                        }
                    }
                }
            }
        }
        int ans = getAns();
        printf("Maximum weight: %d gram(s)\n", ans);
    }

    return 0;
}

原文地址:https://www.cnblogs.com/xuesu/p/10357074.html

时间: 2024-10-06 07:21:53

Uva LV 2995 Image Is Everything 模拟,坐标映射,视图映射 难度: 1的相关文章

uva 10881 Piotr&#39;s Ants (模拟)

uva 10881 Piotr's Ants "One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords."Kent Brockman Piotr likes playing with ants. He has n of them on a horizontal pole L cm lo

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】230 - Borrowers(map模拟)

利用map<string,int>判断一本书的状态,0代表借出去了,1代表在书架,2代表借出去换回来但是还未放回书架 设计一些字符串的处理问题,用一些字符串搜索函数比如 strstr , strchar等等 14072706 230 Borrowers Accepted C++ 0.015 2014-08-21 02:59:27 AC代码: #include<cstdio> #include<cstring> #include<iostream> #incl

UVA 10881 Piotr&#39;s Ants(模拟)

题目链接:https://vjudge.net/problem/UVA-10881 其实这道题的关键只有一句话: 当两个蚂蚁因碰撞而掉头的时候,我们完全可以认为是两个点对穿而过. 这时候我们的主要任务就是弄清楚“谁是谁”. 然而很明显每只蚂蚁的相对顺序是不变的,所以我们要记录一个$order$数组. 预处理出它的初始状态和order,同时算出走之后的状态. 注意程序中的有些地方处理的很巧妙. AC代码: 1 #include<cstdio> 2 #include<iostream>

uva 101 The Blocks Problem (模拟)

uva 101  The Blocks Problem Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm per

UVA 706 LCD Display 液晶显示屏 (字符串模拟)

[题目链接]click here~~ [题目大意] 给定的数字序列,按照要求输出对应液晶显示屏上的数字 输入: 2 12345 3 67890 0 0 输出: -- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | |

UVA - 12108 Extraordinarily Tired Students(模拟)

Extraordinarily Tired Students Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of hi

ACM学习历程——UVA 127 &quot;Accordian&quot; Patience(栈;模拟)

Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patience, the rules for which are as follows: Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate n

UVA 1596 Bug Hunt (大模拟 栈)

题意: 输入并模拟执行一段程序,输出第一个bug所在的行. 每行程序有两种可能: 数组定义: 格式为arr[size]. 例如a[10]或者b[5],可用下标分别是0-9和0-4.定义之后所有元素均为未初始化状态. 赋值语句: 格式为arr[index]=value. 或者arr[index] = arr[arr[index]]. 例如a[0]=3或者a[a[0]]=a[1]. 赋值语句和数组定义可能会出现两种bug: 下标index越界: 使用未初始化的变量(index和value都可 能出现