40分,1000带进去不对,求助/(ㄒoㄒ)/~~

P2669 [NOIP2015 普及组] 金币

m3o7o2n1 @ 2024-02-06 16:10:55

#include <stdio.h>
int main(){
    int k,i,sum=0,a[100000],j=0,t,m=0;
    scanf("%d",&k);
    for(i=1;j<k;i++){
        for(;m<i;j++){
            a[j]=i;
            m=m+1;
        }
        m=0;
    }
    for(t=0;t<=j;t++)sum=sum+a[t];
    printf("%d",sum);
    return 0;
}

by dzsf_lhz @ 2024-02-17 12:56:14

@m3o7o2n1

如果实在看不出来就换一种写法

Code

#include <iostream>
using namespace std;
int n, cnt = 0, ans;
int main(){
    cin >> n;
    while(n >= cnt) //可以连续cnt天发cnt 枚
        n -= cnt, ans += cnt * cnt, cnt ++;
    if(n) ans += cnt * n;
    cout << ans;
    return 0;
}

本蒟蒻看不出来


by jiang0218 @ 2024-12-04 21:27:01

可以试一下我这种

#include<iostream>
using namespace std;
int main(){
    int a = 1;

    //int cnt;

    int day = 0;

    int money = 0;

    int c;

    cin >> c;

    int m;

    int cnt = 1;

    int ture = 2;

    int f = 1;

    while(ture > 0){
        money = money + cnt;
        if(f == c){
              cout << money; 
            break;
        }
        day++;
        f++;
        //money = money + cnt;

        if(day == cnt){
            day = 0;
            cnt++;
            a++;
        }

    }
}

|