LA 2995 & ZOJ2714 Image is Everything

本文介绍了一种通过分析物体六个方向的图像来估算其最大可能重量的算法。该算法适用于小型轻质物体,并考虑了物体由立方体网格构成的情况。通过输入不同视角的图像数据,程序能够计算出物体的最大重量。
Image is Everything

Time Limit: 2 Seconds Memory Limit: 65536 KB

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 6 cardinal directions, and then inferring an upper limit on the object's weight based on those images. You must write a program to do that for the robot.

You can assume that each object is formed from an N*N*N lattice of cubes, some of which may be missing. Each 1*1*1 cube weighs 1 gram, and each cube is painted a single solid color. The object is not necessarily connected.

Input

The 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 <=10). The next N lines are the different N*N views of the object, in the order front, left, back, right, top, bottom. Each view will be 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 are represented by single, unique capital letters, while a period (.) indicates that the object can be seen through at that location.

Input for the last test case is followed by a line consisting of the number 0.

Output

For 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.
2
ZZ ZZ ZZ ZZ ZZ ZZ
ZZ ZZ ZZ ZZ ZZ ZZ
0

Sample Output

Maximum weight: 11 gram(s)
Maximum weight: 8 gram(s)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define FOR(i,n) for(int i=1; i<=n; i++)
#define FORDAO(i,n) for(int i=n; i>0; i--)
const int MAXN = 15;
char view[MAXN][MAXN][MAXN][10];
bool islive[MAXN][MAXN][MAXN];
int n;
char read_char()
{
    char rt;
    while(true)
    {
        rt = getchar();
        if((rt>='A'&&rt<='Z') || rt=='.')return rt;
    }
}
void deleteone(int x, int y, int z)
{
    int a;
    for(a=1;!islive[x+a][y][z];a++);
    view[x+a][y][z][5] = view[x][y][z][5];
    for(a=1;!islive[x-a][y][z];a++);
    view[x-a][y][z][6] = view[x][y][z][6];
    for(a=1;!islive[x][y+a][z];a++);
    view[x][y+a][z][2] = view[x][y][z][2];
    for(a=1;!islive[x][y-a][z];a++);
    view[x][y-a][z][4] = view[x][y][z][4];
    for(a=1;!islive[x][y][z+a];a++);
    view[x][y][z+a][3] = view[x][y][z][3];
    for(a=1;!islive[x][y][z-a];a++);
    view[x][y][z-a][1] = view[x][y][z][1];
    islive[x][y][z] = false;
}
bool check(int x, int y, int z)
{
    char color='a';
    FOR(k,6)
    {
        if(view[x][y][z][k]=='.')return false;
        if(view[x][y][z][k]=='a')continue;
        if(view[x][y][z][k]==color || color=='a')
        {
            color = view[x][y][z][k];   
        }else{
            return false;
        }
    } 
    return true;
}
bool work()
{
    bool rt = false;
    FOR(x,n) FOR(y,n) FOR(z,n)
    if(islive[x][y][z] && !check(x,y,z))
    {
        deleteone(x,y,z);
        rt = true;
    }
    return rt;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)break;
        FOR(x,n)FOR(y,n)FOR(z,n)FOR(k,6)view[x][y][z][k] = 'a';
        memset(islive,1,sizeof islive);
        FOR(x,n)
        {
             FOR(y,n) view[x][y][1][3] = read_char();
             FORDAO(z,n) view[x][1][z][2] = read_char();
             FORDAO(y,n) view[x][y][n][1] = read_char();
             FOR(z,n) view[x][n][z][4] = read_char();
             FOR(y,n) view[1][y][n-x+1][5] = read_char();
             FOR(y,n) view[n][y][x][6] = read_char(); 
        }
         
        while(work());
        int ans = 0;
        FOR(i,n) FOR(j,n) FOR(k,n) 
        if(islive[i][j][k]) ans++;
        printf("Maximum weight: %d gram(s)\n",ans); 
    }
    return 0;
}


【复现】并_离网风光互补制氢合成氨系统容量-调度优化分析(Python代码实现)内容概要:本文围绕&ldquo;并_离网风光互补制氢合成氨系统容量-调度优化分析&rdquo;的主题,提供了基于Python代码实现的技术研究与复现方法。通过构建风能、太阳能互补的可再生能源系统模型,结合电解水制氢与合成氨工艺流程,对系统的容量配置与运行调度进行联合优化分析。利用优化算法求解系统在不同运行模式下的最优容量配比和调度策略,兼顾经济性、能效性和稳定性,适用于并网与离网两种场景。文中强调通过代码实践完成系统建模、约束设定、目标函数设计及求解过程,帮助读者掌握综合能源系统优化的核心方法。; 适合人群:具备一定Python编程基础和能源系统背景的研究生、科研人员及工程技术人员,尤其适合从事可再生能源、氢能、综合能源系统优化等相关领域的从业者;; 使用场景及目标:①用于教学与科研中对风光制氢合成氨系统的建模与优化训练;②支撑实际项目中对多能互补系统容量规划与调度策略的设计与验证;③帮助理解优化算法在能源系统中的应用逻辑与实现路径;; 阅读建议:建议读者结合文中提供的Python代码进行逐模块调试与运行,配合文档说明深入理解模型构建细节,重点关注目标函数设计、约束条件设置及求解器调用方式,同时可对比Matlab版本实现以拓宽工具应用视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值