T641800题解

· · 个人记录

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

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

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

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

#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;
}