sdutacm-Sorting It All Out

 

Sorting It All Out

Time Limit: 1000MS MemoryLimit: 10000KB

SubmitStatistic

ProblemDescription

Anascending sorted sequence of distinct values is one in which some form of aless-than operator is used to order the elements from smallest to largest. Forexample, the sorted sequence A, B, C, D implies that A < B, B < C and C< D. in this problem, we will give you a set of relations of the form A <B and ask you to determine whether a sorted order has been specified or not.

Input

Inputconsists of multiple problem instances. Each instance starts with a linecontaining two positive integers n and m. the first value indicated the numberof objects to sort, where 2 <= n <= 26. The objects to be sorted will bethe first n characters of the uppercase alphabet. The second value m indicatesthe number of relations of the form A < B which will be given in thisproblem instance. Next will be m lines, each containing one such relationconsisting of three characters: an uppercase letter, the character"<" and a second uppercase letter. No letter will be outside therange of the first n letters of the alphabet. Values of n = m = 0 indicate endof input.

Output

Foreach problem instance, output consists of one line. This line should be one ofthe following three: 

Sorted sequence determined after xxx relations: yyy...y. 
Sorted sequence cannot be determined. 
Inconsistency found after xxx relations. 

where xxx is the number of relations processed at the time either a sortedsequence is determined or an inconsistency is found, whichever comes first, andyyy...y is the sorted, ascending sequence.

ExampleInput

4 6

A<B

A<C

B<C

C<D

B<D

A<B

3 2

A<B

B<A

26 1

A<Z

0 0

ExampleOutput

Sorted sequence determinedafter 4 relations: ABCD.

Inconsistency found after 2relations.

Sorted sequence cannot bedetermined.

Hint

poj1094有链接提示的题目请先去链接处提交程序,AC后提交到SDUTOJ中,以便查询存档。

Author

East Central North America 2001

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int oo=105;
int n,m,in[oo],temp[oo],s,t,pos,num,Sort[oo];
vector<int>g[oo];
queue<int>q;
void init()
{
    memset(in,0,sizeof(in));
    for(int i=0;i<=n;i++)
    g[i].clear();
}
inline bool find(int u,int v)
{
    for(int i=0;i<g[u].size();++i)
    {
        if(g[u][i]==v)return true;
    }
    return false;
}
int toposort()
{
    while(!q.empty())q.pop();
    for(int i=0;i<n;i++)
    {
        if(in[i]==0)
        {
        q.push(i);
        }
    }
    pos = 0;
    bool unsure = false;
    while(!q.empty())
    {
        if(q.size()>1)unsure = true;//假如存在多个起点说明拓扑排序不唯一
        int t = q.front();
        q.pop();
        Sort[pos++] = t;
        for(int i=0;i<g[t].size();i++)
        {
            if(--in[g[t][i]]==0)
            {
                q.push(g[t][i]);
            }
        }
    }
    if(pos<n) return 1;//扫描点个数小于N说明存在环路
    if(unsure) return 2;//继续寻找
    return 3; //发现唯一拓扑排序
}
int main()
{
    int x,y,i,flag,ok,stop;
    while(~scanf("%d%d%*c",&n,&m))
    {
        if(!n||!m)
        {
            break;
        }
        init();
        flag = 2;
        ok  = false;
        char X,O,Y;
        for(i=1;i<=m;i++)
        {
            scanf("%c%c%c%*c",&X,&O,&Y);
            if(ok)continue;//当非(不确定拓扑序列)即单一序列或者出现环时,只输入不处理
            x = X-'A',y = Y-'A';
            if(!find(y,x))//当不存在此路径时
            {
            g[y].push_back(x);
            ++in[x];
            }
            else if(!find(x,y))
            {
            g[x].push_back(y);
            ++in[y];
            }
            memcpy(temp,in,sizeof(in)); // 拷贝一个副本,等下用来还原in数组
            flag = toposort();
            memcpy(in,temp,sizeof(temp));
            if(flag!=2)
            {
                stop = i;
                ok = true;
            }
         }
    if(flag ==3)
    {
    printf("Sorted sequence determined after %d relations: ",stop);
    for(i = pos-1;i>=0;--i)
    {
        printf("%c",Sort[i]+'A');
    }
    printf(".\n");

    }
    else if(flag==1)
    {
    printf("Inconsistency found after %d relations.\n",stop);
    }
    else
    {
        printf("Sorted sequence cannot be determined.\n");
    }

}
return 0;
}


/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 0ms
Take Memory: 164KB
Submit time: 2017-02-20 16:35:15
****************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sorting Group是一个组件,将其添加到一个GameObject上可以确保该GameObject及其子对象中的所有Renderers会一起进行排序和渲染。 针对问题1,要调整image在sprite前面,可以通过修改Image对象的Sorting Order属性来实现。将Sorting Order设置为较大的值,就可以使Image渲染在Sprite前面。 针对问题2,不同Sprite之间的渲染可以通过修改它们各自的Sorting Order属性来进行调整。将需要渲染在前面的Sprite的Sorting Order设置为较大的值,就能够使它们在渲染时出现在其他Sprite的前面。 针对问题3,如果不想改变Z轴的情况下让Sprite渲染在Image前面,可以使用Sorting Layer来调整。首先,确保Image和Sprite所在的Sorting Layer相同。然后,通过修改Sprite的Order in Layer属性,将需要渲染在前面的Sprite的Order in Layer设置为较大的值,就能够使它们在渲染时出现在Image的前面。 综上所述,通过修改Sorting Order和Order in Layer属性,可以实现对GameObject和其子对象的渲染顺序进行调整,以满足UI拼接等需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [UnityEngine.Rendering 之 SortingGroup](https://blog.csdn.net/Game_jqd/article/details/124564072)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [2021-04-13](https://blog.csdn.net/qq_43628118/article/details/115657275)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值