40分!

P2669 [NOIP2015 普及组] 金币

HEROBRINEH @ 2023-12-24 19:35:23

#include<bits/stdc++.h>
using namespace std;
int main(){
    int i=1,z=0,N,t=1;
    cin>>N;
    while(i<=N){
        int j=1;
        while(j<=t){
            z=z+t;
            i++;
            j++;
        }
        t++;
    }
    cout<<z;
    return 0;
}

求解


by qxs_ck @ 2023-12-24 20:15:06

@HEROBRINEH

#include<bits/stdc++.h>
using namespace std;
int main(){
    int i=1,z=0,N,t=1;
    cin>>N;
    while(i<=N){
        int j=1;
        while(j<=t){
            z+=t;
            i++;
            j++;
            if(i>N) break;
        }
        t++;
    }
    cout<<z;
    return 0;
}

while也要判断天数是否超过


by HEROBRINEH @ 2023-12-24 20:16:52

谢谢你,已关


|