英语翻译An ascending sorted sequence of distinct values is one i
- 提问者网友:wodetian
- 2021-05-21 19:48
An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest.For example,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
Input consists of multiple problem instances.Each instance starts with a line containing two positive integers n and m.the first value indicated the number of objects to sort,where 2
- 五星知识达人网友:冷風如刀
- 2021-05-21 20:48
是清华的ACM试题吧,我刚做完,你试试看.
#include
using std::cout;
using std::cin;
using std::endl;
struct item{
char key;
int priority;
struct item** smaller;
struct item** greater;
};
typedef struct item Item;
int placeToAdd(Item** a,char b,int n){
int i;
for(i=0;ikey)==b) return i;
else if((a[i]->key)==' ') {
a[i]->key=b;
return i;
}
}
if(i>=n) return -1;
}
int hasCompared(Item** a,int i,int j,int n){
int m=0;
if(i==j)return -1;
while((((a[i]->greater[m])!=0||a[i]->smaller[m])!=0)&&mgreater[m])==a[j]) return 1;
else if((a[i]->smaller[m])==a[j]) return -1;
m++;
}
if(mgreater[m]=a[j];
m=0;
while((a[j]->smaller[m])!=0&&mpriority>=a[j]->priority) a[j]->priority=a[i]->priority+1;
int k=0;
while((a[j]->greater[k])!=0&&kgreater[k]->priority+=1;
k++;
}
return 0;
}
}
int main(){
int l,m,n,i,j;
int unsorted=0,inconsistent=0;
char sign,first,second;
cin>>m>>n;
if(m==0||n==0){
coutgreater[j]=0;
}
}
l=n;
while(n>0){
cin>>first>>sign>>second;
i=placeToAdd(a,first,m);
j=placeToAdd(a,second,m);
if(i!=-1&&j!=-1){
if(keySetting(i,j,a,m)==-1) inconsistent=1;
}
else unsorted=1;
n--;
}
if(unsorted) cout