70分求调有注释QAQ
查看原帖
70分求调有注释QAQ
1324360
S1eepy1楼主2024/10/1 17:01
#include<iostream>
#include<cstdio>
#include<queue>
#include<string.h>
using namespace std;
#define MAXN 3010
#define INF 10086
char s[MAXN][MAXN];
struct node{
    int x;
    bool operator < (const node &a)const
    {
        return x>a.x;
    }
};
int a[MAXN];
void set_1(int n)
{
    for(int i=0;i<n;++i)a[i]=1;
}
signed main()
{

    int n,m;
    scanf("%d%d",&n,&m);
    set_1(n);
//    for(int i=0;i<n;++i)
//    {
//        scanf("%s",s[i]);
//    }
    for(int i=0;i<n;++i)
    {
        int j=0;
        char ch='0';
        while(ch!='\n')
        {
            if(j==m)
            {
                break;
            }
            scanf("%c",&ch);
            if(ch!='\n')
            {
                s[i][j]=ch;
            }
            else
            {
                ch='0';
                continue;
            }
            ++j;
        }
    }//读取输入
//    cout<<minn<<endl;
    for(int i=0;i<n;++i)
    {
        priority_queue<node> ttmp;//优先队列
        for(int j=0;j<m;++j)
        {
            node nod;
            nod.x=s[i][j]-'a';
            ttmp.push(nod);
        }
        int tmp[MAXN];//优先队列无法直接访问下标,因此多开个数组
        for(int j=0;j<m;++j)
        {
            tmp[j]=ttmp.top().x;
            ttmp.pop();
        }
        for(int j=0;j<n;++j)
        {
            int rec=0;
            if(j==i)continue;//跳过自己
            int jrec=s[j][rec]-'a';
            if(tmp[rec]<jrec)
            {
                continue;
            }
            else if(tmp[rec]>jrec)
            {
                a[i]=0;
                break;
            }
            else
            {
                while(tmp[rec]==s[j][rec]-'a')
                {
                    rec++;
                }
                if(tmp[rec]>s[j][rec])//前面几位一样,比较后面不一样的字符
                {
                    a[i]=0;
                    break;
                }
            }
        }
    }
    for(int i=0;i<n;++i)
    {
        printf("%d",a[i]);
    }
    return 0;
}


2024/10/1 17:01
加载中...