zoukankan      html  css  js  c++  java
  • 1030

     

    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$ le$N$ le$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<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int MaxN=10+5;
    char g1[MaxN][MaxN],g2[MaxN][MaxN],g3[MaxN][MaxN],g4[MaxN][MaxN],g5[MaxN][MaxN],g6[MaxN][MaxN];
    int p1[MaxN][MaxN],p2[MaxN][MaxN],p3[MaxN][MaxN],p4[MaxN][MaxN],p5[MaxN][MaxN],p6[MaxN][MaxN];
    int g[MaxN][MaxN][MaxN];
    int n;
    
    void init();
    void work();
    bool update_front();
    bool update_left();
    bool update_back();
    bool update_right();
    bool update_top();
    bool update_bottom();
    
    int main()
    {
    	for(;;)
    	{
    		scanf("%d",&n);
    		if(n==0) break;
    		init();
    		work();
    	}
    	return 0;
    }
    
    void init()
    {
    	for(int i=0;i<n;++i)
    		scanf("%s %s %s %s %s %s",g1[i],g2[i],g3[i],g4[i],g5[i],g6[i]);
    }
    
    void work()
    {
    	fill(p1[0],p1[n],0);fill(p2[0],p2[n],0);fill(p3[0],p3[n],0);
    	fill(p4[0],p4[n],0);fill(p5[0],p5[n],0);fill(p6[0],p6[n],0);
    	fill(g[0][0],g[n][0],-1);
    	for(;;)
    	{
    		bool quit=true;
    		if(update_front()) quit=false;
    		if(update_left()) quit=false;
    		if(update_back()) quit=false;
    		if(update_right()) quit=false;
    		if(update_top()) quit=false;
    		if(update_bottom()) quit=false;
    		if(quit) break;
    	}
    	int ans=n*n*n;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    			for(int k=0;k<n;++k)
    				if(g[i][j][k]==0) --ans;
    	printf("Maximum weight: %d gram(s)
    ",ans);
    }
    
    bool update_front()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p1[i][j];
    			char ch=g1[i][j];
    			if(t==n) continue;
    			int &val=g[n-t-1][j][i];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    
    bool update_left()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p2[i][j];
    			char ch=g2[i][j];
    			if(t==n) continue;
    			int &val=g[j][t][i];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    
    bool update_back()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p3[i][j];
    			char ch=g3[i][j];
    			if(t==n) continue;
    			int &val=g[t][n-j-1][i];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    
    bool update_right()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p4[i][j];
    			char ch=g4[i][j];
    			if(t==n) continue;
    			int &val=g[n-j-1][n-t-1][i];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    
    bool update_top()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p5[i][j];
    			char ch=g5[i][j];
    			if(t==n) continue;
    			int &val=g[i][j][t];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    
    bool update_bottom()
    {
    	bool upd=false;
    	for(int i=0;i<n;++i)
    		for(int j=0;j<n;++j)
    		{
    			int &t=p6[i][j];
    			char ch=g6[i][j];
    			if(t==n) continue;
    			int &val=g[n-i-1][j][n-t-1];
    			if(val==0)
    			{
    				++t;
    				upd=true;
    			}
    			else if(ch=='.')
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    			else if(val==-1)
    			{
    				val=ch-'A'+1;
    				upd=true;
    			}
    			else if(val!=ch-'A'+1)
    			{
    				val=0;
    				++t;
    				upd=true;
    			}
    		}
    		return upd;
    }
    


  • 相关阅读:
    如何用nginx将vue部署到本地
    数组中引用类型的去重
    关于element 上传文件el-upload
    ----vue3.0 如何拿到 有ref属性的元素;
    关于 el-form rules校验
    x-www-form-urlencoded 传参
    哈哈 v-model 传递参数给子组件
    记 el-tabs el-tab-pane 中嵌套 router-view出现的问题
    nginx跨域
    css3---flex三剑客
  • 原文地址:https://www.cnblogs.com/pangblog/p/3290120.html
Copyright © 2011-2022 走看看