跳到正文

学习·文化课

集训笔记

pidou约 7 分钟
原文
文章信息与版本

文章信息

发布
2025年9月10日
收录
2026年8月20日
更新
2026年11月12日
篇幅
约 7 分钟

版本

  1. v1当前

暴力出奇迹,骗分过样例。 数学先打表,DP看运气。 穷举变RE,递推UKE。 模拟MLE,贪心还CE。 想要骗到分,就要有方法。 图论背模板,数论背公式。 动规背方程,高精背代码。 如果都没背,干脆输样例

C++
#include<bits/extc++.h>  
using namespace __gnu_pbds;

vector<int> v;
int sum = v.accumulate(v.begin(), v.end(), 0);
int maxx = *v.max_element(v.begin(), v.end());
int minn = *v.min_element(v.begin(), v.end());
C++
puts("");  printf("");

和

C++
cin.tie(0)->sync_with_stdio(0);

不能混用
快读模板

C++
#include<bits/stdc++.h>
using namespace std;
uint8_t rbuf[1<<20], *p1, *p2;
#define gc() (p1==p2 && (p2=(p1=rbuf)+fread(rbuf,1,1<<20,stdin))?EOF:*p1++)
#define rep(i,x,y)  for(int i=(x);i<=(y);i++)
using ll = long long;
inline int read(){
    int k = 0, f = 1, c = gc();
    for (; !isdigit(c); c = gc()) if (c == '-') f = -1;
    for (; isdigit(c); c = gc()) k = (k << 3) + (k << 1) + (c ^ 48);
    return k * f;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    return 0;
}

链表

C++
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y)  for(int i=(x);i<=(y);i++)
using ll = long long;
struct node{
	int data;
	node *next;
};
node *head = nullptr;
node *tail = nullptr;
void add(int val){
	node *node1 = new node;
	node1->data = val;
	node1->next = nullptr;
	if(head == nullptr){
		head = tail = node1;
	}
	else{
		tail->next = node1;
		tail = node1;
	}
}
void print(){
	node *cur = head;
	while(cur != nullptr){
		cout<<cur->data<<' ';
		cur = cur->next;
	}
	cout<<'\n';
}
void insert1(int x){
	node *node1 = new node;
	node1->data = x;
	node1->next = head;
	head = node1;
	if(tail == nullptr){
		tail = node1;
	}
}
void insert2(int x, int num){
	node *cur = head;
	while(cur != nullptr){
		if(cur->data == num){
			node *node1 = new node;
			node1->data = x;
			node1->next = cur->next;
			cur->next = node1;
			if(cur == tail){
				tail = node1;
			}
			break;
		}
		cur = cur->next;
	}
}
void insert3(int x, int index){
	if(index < 0) return;
	if(index == 0){
		insert1(x);
		return;
	}
	node *cur = head;
	int pos = 1;
	while(cur != nullptr && pos < index){
		cur = cur->next;
		pos++;
	}
	if(cur == nullptr) return;
	node *node1 = new node;
	node1->data = x;
	node1->next = cur->next;
	cur->next = node1;
	if(cur == tail){
		tail = node1;
	}
}
void del1(){
	if(head == nullptr) return;
	node *tmp = head;
	head = head->next;
	if(head == nullptr) tail = nullptr;
	delete tmp;
}
void del2(int x){
	if(head == nullptr) return;
	node *cur = head;
	node *pre = nullptr;
	while(cur != nullptr && cur->data != x){
		pre = cur;
		cur = cur->next;
	}
	if(cur == nullptr) return;
	if(cur == head){
		head = head->next;
		if(head == nullptr) tail = nullptr;
	}
	else{
		pre->next = cur->next;
		if(cur == tail) tail = pre;
	}
	delete cur;
}
void reverse(){
	node *pre = nullptr;
	node *cur = head;
	node *nxt = nullptr;
	while(cur != nullptr){
		nxt = cur->next;
		cur->next = pre;
		pre = cur;
		cur = nxt;
	}
	tail = head;
	head = pre;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		add(x);
	}
	print();//10 20 30
	
	insert1(5);//5 10 20 30
	print();
	
	insert2(25, 20);//5 10 20 25 30
	print();
	
	insert3(15, 2);//5 10 15 20 25 30
	print();
	
	del1();//10 15 20 25 30
	print();
	
	del2(30);//10 15 20 25
	print();
	
	reverse();//25 20 15 10
	print();
    return 0;
}
priority_queue<int> p;
原文
抓取于
  1. pidou

    pidou