Gym 100917 A. Abstract Picture

185 篇文章 0 订阅
50 篇文章 0 订阅
Famous abstract painter Va Sya plans to start new painting. It will be composed as square with grid n × n, where each unit square is painted by some color.

Va Sya already defined the colors for some unit squares. Color of other squares does not matter for him.

For this work Va Sya is planning use the continuous technics: he paints whole row or whole column in some color. Moreover, each row and each column must be painted exactly once, so each unit square will be painted twice and its final color will be the last of two used colors.

Help Va Sya to find appropriate sequence of paints.

Input

First line of the input contains one integer n — length of the painting side in units (1 ≤ n ≤ 3000).

Each of the next n lines contains n characters. If i-th character inj-th line equals to '?', it means that color ofi-th cell in j-th row of painting does not matter. Otherwise it contains lowercase English letter from 'a' to 'z' inclusively, which represents the color of corresponding cell (it is well known that Va Sya uses only 26 colors).

Output

Print 2n lines, i-th of those lines contains description of i-th paint in the following format:

«h yc» — rowy is painted with colorc;

«v xc» — columnx is painted with colorc.

Rows are numbered sequentially upside down, columns are numbered sequentially leftside right, so upper left corner is on intersection of row 1 and column 1. Each row and each column must be mentioned in the output exactly once.

You may assume that there exists at least one solution for the given input. If there are several correct solutions, print any of them.

Example
Input
3
ac?
ab?
?cz
Output
h 1 p
h 3 q
v 2 c
h 2 b
v 1 a
v 3 z

   分析:正解还是很好想的,最后染色的行或列的颜色一定最多只有一种,于是我们倒着来每次把颜色种类小于等于1的行或列记入答案并删除,细节有点多导致那天调了一下
下午没找到错,后来写了一个对拍发现是自己在处理'?'时太粗心了。
 
#include <cstdio>
#include <iostream>
using namespace std;
struct HL
{
    int tot,ch[27];
} hl[2][3001];
int tot,ans[6001][3],z[6001][2],n,num,f[3001][3001];
bool jud[2][3001];
char c;
int Find(int x,int i)
{
    for(int j=1;j <= 26;j++)
     if(hl[x][i].ch[j] > 0) return j;
    return 0;
}
int main()
{
    scanf("%d%*c",&n);
    for(int i=1;i <= n;i++)
    {
      for(int j=1;j <= n;j++)
      {
        scanf("%c",&c);
        if(c != '?')
        {
           hl[0][i].ch[c-'a'+1]++;
           hl[1][j].ch[c-'a'+1]++;
           f[i][j]=c-'a'+1;
        }
      }
      scanf("%*c");
    }
    for(int i=1;i <= n;i++)
    {
        for(int j=1;j <= 26;j++)
        {
            if(hl[0][i].ch[j]) hl[0][i].tot++;
            if(hl[1][i].ch[j]) hl[1][i].tot++;
        }
        if(hl[0][i].tot <= 1)
        {
            z[++tot][0]=0;
            z[tot][1]=i;
            jud[0][i]=true;
        }
        if(hl[1][i].tot <= 1)
        {
            z[++tot][0]=1;
            z[tot][1]=i;
            jud[1][i]=true;
        }
    }
    int s=1,t=tot+1;
    while(s != t)
    {
        ans[++num][0]=z[s][0];
        ans[num][1]=z[s][1];
        int col=ans[num][2]=Find(z[s][0],z[s][1]);
        int now=z[s][0];
        if(col)
        {
            for(int i=1;i <= n;i++)
             if(!jud[(now+1)%2][i] && hl[(now+1)%2][i].ch[col]) 
             {
            	if( now == 1 && f[i][z[s][1]]==0 ) continue;
            	if( now == 0 && f[z[s][1]][i]==0 ) continue;
                hl[(now+1)%2][i].ch[col]--; 
                if(hl[(now+1)%2][i].ch[col] == 0) hl[(now+1)%2][i].tot--;
                if(hl[(now+1)%2][i].tot <= 1)
                {
                    z[t][0]=(now+1)%2;
                    z[t][1]=i;
                    jud[(now+1)%2][i]=true;
                    t++;
                }
             }
        }
        s++;
    }
   for(int i=2*n; i >= 1;i--)
    if(ans[i][0] == 0) cout<<"h "<<ans[i][1]<<" "<<char(max(1,ans[i][2])+'a'-1)<<endl;
    else cout<<"v "<<ans[i][1]<<" "<<char(max(1,ans[i][2])+'a'-1)<<endl;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自2020年以来,自动驾驶汽车(Autonomous Vehicle)在这一领域取得了显著进展。 自动驾驶汽车通过使用先进的传感技术,如雷达、激光雷达和摄像头,以及深度学习和人工智能算法,实现了车辆的自主驾驶。它们能够感知周围环境,了解道路状况,并做出相应的决策和行驶动作,从而实现无需人类操控的车辆行驶。 自动驾驶汽车在2020年迅速崭露头角。它们的技术日益成熟,不断的实验和测试表明其在安全性和性能方面已经取得了显著的突破。虽然仍然存在一些挑战,比如在复杂城市环境中导航和处理紧急情况,但这些问题正经过不断的研究和改进来得以解决。 在未来,自动驾驶汽车有望在各个领域发挥重要作用。首先,它们将可以提高道路交通的安全性。由于自动驾驶车辆不受人类司机的疲劳、分心和驾驶误差的限制,它们的驾驶能力更为稳定和准确。其次,自动驾驶汽车还能够提高交通效率。通过与其他车辆实时通信和协同,它们可以避免交通堵塞和减少事故发生,从而减少交通拥堵和行车时间成本。 此外,自动驾驶汽车也将为交通出行带来便利和舒适性。乘客可以更轻松地进行其他活动,如工作、休息或娱乐,而不必担心驾驶问题。老年人和残障人士也将能够自由独立地出行,提高他们的生活质量。 综上所述,作为2020年的重要趋势,自动驾驶汽车具有广阔的应用前景。通过不断的创新和发展,它们将在道路交通安全、交通效率和出行体验方面取得进一步的提升。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值