跳到正文

个人记录

T641800题解

2021王艺乔约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年7月27日
收录
2025年12月12日
更新
2026年9月22日
篇幅
约 1 分钟

版本

  1. v1当前

这道题作为考试的T1显然是一道简单题,根据题意模拟即可。

level表示等级,lef表示余下的经验球数目。每次的增加操作,先将经验球加到lef中。根据题意,从level升到level+1级所消耗的经验球数目为level+7点。因此直接暴力模拟升级过程,一直升到不能再升级为止。

由于题目数据保证 n≤1000,最终答案x≤10000n\leq1000,最终答案x\leq10000 ,时间复杂度为 O(n+x)O(n+x) ,能够通过。

(其实这题数据还能开的更大但作为T1没必要,根据升级所需经验是等差数列的性质能够O(1)算出每次增加经验能升多少级,解一个二次方程就行)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,op,x,level,lef;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>op;
		if(op==1){
			cin>>x;
			lef+=x;
			while(lef>=level+7){
				lef-=level+7;
				level++;
			}
		}
		else{
			cout<<level<<"\n";
		}
	}
	return 0;
}
原文