跳到正文

个人记录

20260818总结(来追梦)

china_lfy约 8 分钟
原文
文章信息与版本

文章信息

发布
2026年8月18日
收录
2026年8月20日
更新
2026年11月16日
篇幅
约 8 分钟

版本

  1. v2当前
  2. v1

考试情况

题目得分
T1100

题目总结

T1

正确代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
priority_queue<int> q;
int n;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int f,x;
		cin>>f;
		if(f==1){
			cin>>x;
			q.push(x);
		}else if(f==2){
			cout<<q.top()<<"\n";
			//q.pop();
		}else{
			q.pop();
		}
	}
	return 0;
} 

T2

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
priority_queue<string,vector<string>,greater<string>> q;
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,f;
		string s;
		cin>>f;
		if(f==1){
			cin>>s;
			q.push(s);
		}else{
			cin>>x;
			if(x==1){
				if(q.size()==0){
					cout<<"NOT FOUND"<<"\n";
				}else{
					cout<<q.top()<<"\n";
					q.pop();
				}
			}else{
				if(q.size()==0){
					cout<<"NOT FOUND"<<"\n";
				}else{
					cout<<q.top()<<"\n";
				}
			}
		}
	}
	return 0;
} 

T3

错误原因:long long *long long 会错

C++
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int n,m;
int ans;
priority_queue<int,vector<int>,greater<int>> q;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		q.push(x);
	}
	while(q.size()>1){
		int x=q.top();
		q.pop();
		int y=q.top();
		q.pop();
		if(m*x>=y&&m*y>=x)ans++;
		q.push(x+y);
	}
	cout<<ans;
	return 0;
}

正确代码:

C++
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int n,m;
int ans;
priority_queue<int,vector<int>,greater<int>> q;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		q.push(x);
	}
	while(q.size()>1){
		int x=q.top();
		q.pop();
		int xx=q.top();
		q.pop();
		int f=0;
		if(xx%m==0&&x>=xx/m||xx%m!=0&&x>xx/m)f++;
		if(x%m==0&&xx>=x/m||x%m!=0&&xx>x/m)f++;
		if(f==2)ans++;
		q.push(x+xx);
	}
	cout<<ans;
	return 0;
}

T4

错误原因:没思路

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int a[200005];
int s[200005];
int d[200005];
signed main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)cout<<"-1"<<"\n";
	return 0;
}
正确代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
ll a[200005];
ll b[200005];
ll d[200005];
ll c[200005];
ll v[200005];
ll vis[200005];
struct node{
	int t,x,id;
	bool operator<(const node &x)const{
		return t>x.t;
	}
};
priority_queue<node> q;
int main(){
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		cin>>v[i];
	}
	for(ll i=1;i<=m;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		while(!q.empty()){
			node now=q.top();
			if(now.t>a[i])break;
			q.pop();
			v[now.id]+=now.x;
		}
		if(v[b[i]]>=d[i]){
			q.push({a[i]+c[i],d[i],b[i]});
			cout<<v[b[i]]-d[i]<<"\n";
			v[b[i]]-=d[i];
		}else{cout<<"-1\n";}
	}
	return 0;
}

T5

错误原因:方法用错了

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int a[100005];
struct node{
	int id,dp;
	bool operator<(const node &x)const{
		return dp<x.dp;
	}
};
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		priority_queue<node> q;
		for(int i=1;i<=n;i++){
			int sum=0;
			cin>>a[i];
			int x=a[i];
			while(a[i]>=10){
				int v=x%10;
				sum+=v;
				x/=10;
			}
			sum+=x;
			q.push({i,sum});
		}
		for(int i=1;i<=n;i++){
			node t=q.top();
			int u=t.id;
			cout<<a[u];
			q.pop();
		}
		cout<<"\n";
	}
	return 0;
} 

正确代码:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		priority_queue<string> q;
		for(int i=1;i<=n;i++){
			string s;
			cin>>s;
			q.push(s);
		}
		string ans;
		while(!q.empty()){
			string ss=q.top();
			q.pop();
			ans+=ss[0];
			if(ss.size()>0)ss.erase(0,1);
			if(ss.size())q.push(ss);
			
		}
		cout<<ans<<"\n";
	}
	return 0;
} 

刷题刷少了

原文