PAT 天梯赛初赛

L2-009. 抢红包

#include
#include
#include
#include
#include
#include
using namespace std;
int N;
struct node{
	int id;
	double money;
	int cnt;
	node(){
		id=-1;
		money=0;
		cnt=0;
	}
}person[10001];
int com(struct node a,struct node b){
	if(a.money==b.money){
		if(a.cnt==b.cnt){
			return a.idb.cnt;
	}
	return a.money>b.money;
}
int main(){
	int id,k;
	double mon;
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",&k);
		person[i].id=i;
		double total=0;
		for(int j=0;j
L2-010 抢座位 (并查集)
#include
#include
#include
#include
#include
using namespace std;
int relation[101][101],N,M,K;
int f[101];
int find(int x){
	if(x!=f[x]){
		f[x]=find(f[x]);
	}
	return f[x];
}
int main(){
	int a,b,c;
	scanf("%d%d%d",&N,&M,&K);
	for(int i=0;i<=N;i++){
		f[i]=i;
	}
	for(int i=0;i
L2-011 玩转二叉树
#include
#include
#include
#include
#include
using namespace std;
int in[31],pre[31];
struct node{
	int num;
	struct node*left;
	struct node*right;
};
typedef struct node*Tree;

Tree build(int in_s,int in_e,int pre_s,int pre_e){
	if((in_e-in_s)!=(pre_e-pre_s)) return NULL;
	if(in_s>in_e||(pre_s>pre_e)) return NULL;
	Tree t=(Tree)malloc(sizeof(struct node));
	if(!t) return 0;
	t->num=pre[pre_s];
	t->left=NULL;
	t->right=NULL;
	int i;
	for(i=in_s;i<=in_e;i++){
		if(in[i]==pre[pre_s]){
			break;
		}
	}
	if(i>in_s){
		int ll=i-in_s;
		if(ll==0) return t;
		t->left=build(in_s,i-1,pre_s+1,pre_s+ll);
	}
	if(iright=build(i+1,in_e,pre_e-ll+1,pre_e);
	}
	return t;
}
void level(Tree T){
	if(T==NULL) return ;
	queueq;
	q.push(T);
	Tree t;
	int flag=0;
	while(!q.empty()){
		t=q.front();
		q.pop();
		if(!flag){
			printf("%d",T->num);
			flag=1;
		}
		else{
			printf(" %d",t->num);
		}
		if(t->right){
			q.push(t->right);
		}
		if(t->left){
			q.push(t->left);
		}
	}
	return ;
}
int main(){
	int N;
	Tree T;
	scanf("%d",&N);
	for(int i=0;i
L2-012 关于堆的判断
#include
#include
#include
#include
#include
using namespace std;
int N,M;
int h[1001];
void update(int n){
  if(n==1) return ;
  int t;
  int child=n,parent;
  for(;child>1;child=parent){
    parent=child/2;
    if(h[child]1&&y!=x)){
      return 1;
    }
    else{
      return 0;
    }
  }
  else if(num==2){
    if(y/2==x&&(x>0)) return 1;
    else return 0;
  }
  else{
    if(x/2==y&&(y>0)) return 1;
    else return 0;
  }
  return 0;
}

int main(){
  int tmp;
  scanf("%d%d",&N,&M);
  for(int i=1;i<=N;i++){
    scanf("%d",&h[i]);
    update(i);
  }
//  for(int i=1;i<=N;i++){
//  	cout<>str[j];
      char ch=getchar();
      if(ch=='\n') break;
    }
    if(j==3){
      int tmp;
      sscanf(str[0].c_str(),"%d",&tmp);
      if(h[1]==tmp){
        printf("T\n");
      }
      else{
        printf("F\n");
      }
    }
    else if(j==4){
      int tmp1,tmp2;
      sscanf(str[0].c_str(),"%d",&tmp1);
      sscanf(str[2].c_str(),"%d",&tmp2);
      if(find(tmp1,tmp2,1)){
        printf("T\n");
      }
      else{
        printf("F\n");
      }
    }
    else if(j==5){
      string ss=str[3];
      int tmp1,tmp2;
      sscanf(str[0].c_str(),"%d",&tmp1);
      sscanf(str[5].c_str(),"%d",&tmp2);
      if(ss=="parent"){
        if(find(tmp1,tmp2,2)){
          printf("T\n");
        }
        else{
          printf("F\n");
        }
      }
      else if(ss=="child"){
        if(find(tmp1,tmp2,3)){
          printf("T\n");
        }
        else{
          printf("F\n");
        }
      }
    }
  }
  return 0;
}





你可能感兴趣的:(PAT)