Drazil and Tiles CodeForces - 515D

本文探讨了一种算法,用于解决特定条件下的1x2地砖铺设问题,判断铺设方案是否唯一,并在方案唯一时输出具体铺设方式。通过统计空格周围的状态,使用广度优先搜索确保每一步操作的唯一性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:

"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."

But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".

Drazil found that the constraints for this task may be much larger than for the original task!

Can you solve this new problem?

Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2000).

The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.

Output

If there is no solution or the solution is not unique, you should print the string "Not unique".

Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.

Examples

Input

3 3
...
.*.
...

Output

Not unique

Input

4 4
..**
*...
*.**
....

Output

<>**
*^<>
*v**
<><>

Input

2 4
*..*
....

Output

*<>*
<><>

Input

1 1
.

Output

Not unique

Input

1 1
*

Output

*

Note

In the first case, there are indeed two solutions:

<>^
^*v
v<>

and

^<>
v*^
<>v

so the answer is "Not unique".

题意: 铺地砖  < >  ^v  两种方式  看是否铺法唯一 ,若唯一输出铺的方法 ,不唯一输出not unique

解 :统计 . 点周围 四点的 . 的个数 ,如果为1 那么说明他的排列唯一 ,那么他周围的那一个点也确定了 ,周围这个点的点数更新为0 ,与周围这个点 相临近的点 个数全部 - -  ,把个数为1的点又放入队列 ,直到看所有点能不能都被访问

#include <bits/stdc++.h>
using namespace std;
int dir[4][2]= {0,1,0,-1,1,0,-1,0};//方向
char a1[4]= {'<','>','^','v'};
char a2[4]= {'>','<','v','^'};
char m1[2200][2200];//原图
int mm[2200][2200];//四周的.个数
bool v[2200][2200];
int n,m;
int go(int x,int y)
{
    if(x<0) return 0;
    if(x>=n) return 0;
    if(y<0) return 0;
    if(y>=m) return 0;
    if(m1[x][y]!='.') return 0;
    return 1;
}
int cnt;
pair <int,int> p;
queue<pair<int,int> >q;//只存.个数为1的位置
void bfs(int x,int y)
{
    int x1,y1,kk=0;
    v[x][y]=1;
    for(int i=0; i<4; i++)
    {
        x1=x+dir[i][0];
        y1=y+dir[i][1];
        if(go(x1,y1))
        {
            kk++;
            if(!v[x1][y1]) bfs(x1,y1);
        }
    }
    mm[x][y]=kk;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        int sum=0;
        while(!q.empty()) q.pop();
        cnt=0;
        memset(mm,0,sizeof(mm));
        memset(v,0,sizeof(v));
        for(int i=0; i<n; i++)
        {
            scanf("%s",m1[i]);
            for(int j=0; j<m; j++)
                if(m1[i][j]=='.') cnt++;
        }
        if(cnt%2==1)
        {
            printf("Not unique\n");
            continue;
        }
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                if(m1[i][j]=='.'&&!v[i][j])  bfs(i,j);
        memset(v,0,sizeof(v));
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(m1[i][j]=='.'&&mm[i][j]==1)
                {
                    q.push(make_pair(i,j));
                }
            }
        }
        int flag=0;
        while(!q.empty())
        {
            p=q.front();
            q.pop();
            int x1,y1,x2,y2;
            for(int i=0; i<4; i++)
            {
                x1=p.first+dir[i][0];
                y1=p.second+dir[i][1];
                if(go(x1,y1)&&!v[x1][y1])
                {
                    m1[p.first][p.second]=a1[i];
                    m1[x1][y1]=a2[i];
                    mm[x1][y1]=0;
                    v[p.first][p.second]=1;
                    v[x1][y1]=1;
                    for(int j=0; j<4; j++)
                    {
                        x2=x1+dir[j][0];
                        y2=y1+dir[j][1];
                        if(go(x2,y2))
                        {
                            mm[x2][y2]--;
                            if(mm[x2][y2]==1)
                                q.push(make_pair(x2,y2));
                        }
                    }
                }
            }
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
             if(v[i][j]) sum++;
        if(sum!=cnt) printf("Not unique\n");
        else
        {
            for(int i=0; i<n; i++)
            {
                printf("%s\n",m1[i]);
            }
        }
    }
}

//10 10
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*.*.*
//.*.*.*....
//.*.*.*.*.*

 

 
 
 
内容概要:本文档定义了一个名为 `xxx_SCustSuplier_info` 的视图,用于整合和展示客户(Customer)和供应商(Supplier)的相关信息。视图通过连接多个表来获取组织单位、客户账户、站点使用、位置、财务代码组合等数据。对于客户部分,视图选择了与账单相关的记录,并提取了账单客户ID、账单站点ID、客户名称、账户名称、站点代码、状态、付款条款等信息;对于供应商部分,视图选择了有效的供应商及其站点信息,包括供应商ID、供应商名称、供应商编号、状态、付款条款、财务代码组合等。视图还通过外连接确保即使某些字段为空也能显示相关信息。 适合人群:熟悉Oracle ERP系统,尤其是应付账款(AP)和应收账款(AR)模块的数据库管理员或开发人员;需要查询和管理客户及供应商信息的业务分析师。 使用场景及目标:① 数据库管理员可以通过此视图快速查询客户和供应商的基本信息,包括账单信息、财务代码组合等;② 开发人员可以利用此视图进行报表开发或数据迁移;③ 业务分析师可以使用此视图进行数据分析,如信用评估、付款周期分析等。 阅读建议:由于该视图涉及多个表的复杂连接,建议读者先熟悉各个表的结构和关系,特别是 `hz_parties`、`hz_cust_accounts`、`ap_suppliers` 等核心表。此外,注意视图中使用的外连接(如 `gl_code_combinations_kfv` 表的连接),这可能会影响查询结果的完整性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值