指针写挂,求助
  • 板块灌水区
  • 楼主WZKQWQ
  • 当前回复8
  • 已保存回复8
  • 发布时间2020/8/14 15:38
  • 上次更新2023/11/6 20:19:12
查看原帖
指针写挂,求助
239433
WZKQWQ楼主2020/8/14 15:38

#include <bits/stdc++.h>
using namespace std;
double s[100005];
struct shu{
    struct node{
        double *a;
        node *l,*r;
    }*head;
    node* build(int l,int r){
        if(l > r) return NULL;
        int mid = (l + r) >> 1;
        node* tmp = new node;
        tmp -> a = new double(s[mid]);
        if(l == r) return tmp;
        tmp -> l = build(l,mid - 1);
        tmp -> r = build(mid + 1,r);
        return tmp;
    }
    void dfs(node* x){
        if((x -> l) != NULL) dfs(x -> l);
        cout << *(x -> a) << ' ';
        if((x -> r) != NULL) dfs(x -> r);
    }
}t;
int n,m,h;
int main(){
    scanf("%d%d",&n,&h);
    int x,y,z;
    for(int i = 1;i <= n;i++){
        scanf("%d%d",&x,&y);
        s[i] = 1.0 * x / y;
    }
    sort(s + 1,s + 1 + n);
    t.head = t.build(1,n);
    t.dfs(t.head);
    return 0;
}

蒟蒻指针写挂了,望大佬救命QWQ

2020/8/14 15:38
加载中...