关于结构体
  • 板块学术版
  • 楼主卷王慢即快
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/7/11 21:40
  • 上次更新2023/10/27 21:00:26
查看原帖
关于结构体
494699
卷王慢即快楼主2022/7/11 21:40

在做 P1160 时定义了如下结构体:

struct node { int key,pre,next; 
	node(int k,int p,int n) {key=k,pre=p,next=n;}
	node(){} }t[100001];

结果提交上去中全部WA。 然后我稍微修改了一下:

struct node { int pre,next,key; 
	node(int k,int p,int n) {key=k,pre=p,next=n;}
	node(){} }t[100001];

源代码:

//WA代码

#include<bits/stdc++.h>
using namespace std;
struct node { int key,pre,next; 
	node(int k,int p,int n) {key=k,pre=p,next=n;}
	node(){} }t[100001];
int n,m,x,opt,tot=0,f[100001];
inline void ins_back(int x,int y) {
	int now=f[x]; t[++tot]=node(y,now,t[now].next);
	f[y]=tot; t[t[now].next].pre=tot; t[now].next=tot;
} inline void ins_front(int x,int y) {
	int now=f[x]; t[++tot]=node(y,t[now].pre,now);
	f[y]=tot; t[t[now].pre].next=tot; t[now].pre=tot;
} inline void insert(int x) {
	int now=f[x]; int l=t[now].pre,r=t[now].next;
	t[l].next=r;t[r].pre=l; tot--;f[x]=0; 
} int main() { cin>>n; t[0]=node(); ins_back(0,1);
	for(int i=2;i<=n;i++) {
		cin>>x>>opt; opt==1?ins_back(x,i):ins_front(x,i);
	} cin>>m;
	for(int i=1;i<=m;i++) {
		cin>>x; if(f[x]) insert(x);
	} int now=t[0].next;
	while(now) { cout<<t[now].key<<" "; now=t[now].next; }
	return 0; }

本来不抱有希望了,结果……

请问一下为什么??

(注:我赋值时的语句是

t[++tot]=node(y,now,t[now].next);

t[++tot]=node(y,t[now].pre,now);

2022/7/11 21:40
加载中...