社区讨论
【救命啊 80pts】指针循环链表
P1160队列安排参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 6 条
- 当前快照
- 1 份
- 快照标识符
- @lo882any
- 此快照首次捕获于
- 2023/10/27 14:18 2 年前
- 此快照最后确认于
- 2023/10/27 14:18 2 年前
今天我们学校考了这道题,我写了个指针循环链表,只拿了80pts,求调试,谢谢诸位大佬!
求求你们了!!!!!!
CPP#include <bits/stdc++.h>
#define int long long
using namespace std;
struct List{
int data;
List *prev = NULL, *next = NULL;
}*head, *tail;
vector<List*> students;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(int x){
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
signed main(){
int n = read(), m;
students.resize(n + 10);
head = new List;
head->data = 1, students[1] = head;
tail = head, head->prev = tail;
for(int i = 2, k, p; i <= n; i++){
k = read(), p = read();
List *target = students[k], *now = new List;
now->data = i;
if(p == 0){
if(target == head){
now->prev = tail, now->next = head;
head->prev = now, head = now;
goto end;
}
List* tmp = target->prev;
now->next = target, now->prev = tmp;
tmp->next = now, target->prev = now;
}else{
if(target->next == NULL) target->next = now;
List* tmp = target->next;
now->prev = target, now->next = tmp;
tmp->prev = now, target->next = now;
if(target == tail) tail = now, head->prev = tail;
}
end: students[i] = now, tail->next = head;
}
m = read();
for(int i = 1, x; i <= m; i++){
x = read();
students[x]->data = 0;
}
List *it;
for(it = head; it->next != head; it = it->next){
if(it->data == 0) continue;
write(it->data); putchar(' ');
//printf("{address = 0x%x, data = %d, prev = 0x%x, next = 0x%x}\n", it, it->data, it->prev, it->next);
}
if(it->data == 0) return 0;
write(it->data);
return 0;
}
这个代码一出来,整个机房陷入尴尬
回复
共 6 条回复,欢迎继续交流。
正在加载回复...