指针初学者求助!!1
  • 板块P1188 PASTE
  • 楼主wheneveright
  • 当前回复6
  • 已保存回复6
  • 发布时间2021/5/12 20:08
  • 上次更新2023/11/4 23:21:06
查看原帖
指针初学者求助!!1
189351
wheneveright楼主2021/5/12 20:08

这个代码本地和在线 IDE 样例都跑的过去,但是提交全 RE,不知道是哪里出错了 qwq

# include <bits/stdc++.h>
using namespace std;

const int maxn = 100005;

struct reader {
	template <typename Type>
	reader & operator >> (Type & ret) {
		int f = 1; ret = 0; char ch = getchar ();
		for (;!isdigit (ch); ch = getchar ()) if (ch == '-') f = -f;
		for (; isdigit (ch); ch = getchar ()) ret = (ret * 10) + ch - '0';
		ret *= f; return *this;
	}
} fin;

int N, Q;
int L, R, id;
struct ListNode {
	int val;
	ListNode * next, * last;
	ListNode () : val (0) {}
} * head, * now, * Lptr, * Rptr, * Qptr, * Empty;

int main () {
	fin >> N >> Q; now = head = new ListNode ();
	for (int i = 1; i <= N; i++) {
		now -> next = new ListNode();
		now -> next -> last = now;
		now = now -> next; now -> val = i;
	}	now -> next = (Empty = new ListNode ()); 
	while (Q--) {
		fin >> L >> R >> id; Lptr = Rptr = Qptr = head;
		for (int i = 1; i <= N; i++) {
			if (i <= L)  Lptr = Lptr -> next;
			if (i <= R)  Rptr = Rptr -> next;
			if (i <= id) Qptr = Qptr -> next;
			if (i > L && i > R && i > id) break;
		}
		Lptr -> last -> next = Rptr -> next;
		Rptr -> next -> last = Lptr -> last;
		Rptr -> next = Qptr -> next;
		Rptr -> next -> last = Rptr;
		Lptr -> last = Qptr;
		Qptr -> next = Lptr;
	}	now = head;
	for (int i = 1; i <= 10; i++) printf ("%d\n", (now = now -> next) -> val);
	return 0;
}
2021/5/12 20:08
加载中...