/ Vijos / 题库 / 金币 /

题解

74 条题解

  • 6
    @ 2017-11-07 14:40:29
    #include<iostream>
    using namespace std; 
    int main()
    {
        int n,t=1;
        cin>>n;
        int money=1;
        int day=1;
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            
            if(day==0)
            {
                t++;
                day=t;
                money=day;
            }
            sum+=money;
            day--;
            
        }
        cout<<sum;
    }
    
    
    
  • 2
    @ 2017-10-28 16:50:11

    var
    k,i,n:longint;
    begin
    n:=0;
    read(k);
    i:=1;
    while k> i do
    begin
    n:=i*i+ n;
    k:=k-i;
    i:=i+1;
    end;
    if(k> 0) then n := n+i*k;
    write(n);
    end.

  • 1
    @ 2024-08-28 14:57:36

    这道题用数学推导一下就可以了
    思路:
    把领金币的过程分为2种情况:
    一种是完整地用了q天,每天领q个币,一共领到q^2个
    另一种是正在高高兴兴地领着币,但突然到输入的天数k了,这时只能领到x乘n个币(x<n,x为每天领n个币的天数)

    例:
    k=9时,情况如下:
    1
    22
    333
    444|4
    前3行是情况1,最后一行是情况2(最后一个4领不到,这里用|分割)

    易知情况1一共能领到n(n+1)(2n+1)/6个币(n是情况1发生的次数)
    情况2能领到(k-n(n+1)/2)(n+1)个
    答案就是n(n+1)(2n+1)/6 + (k-n(n+1)/2)(n+1).

    但问题是,如何求n?
    我们先假设∑n^2 = k,解得n=(sqrt(8k+1)-1)/2 (∑n^2 = n(n+1)/2),这时只要再floor()取整即可.
    知道了n,答案当然就呼之欲出了

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
        int k, n;
        cin >> k;
        n = floor((sqrt(8*k+1) - 1) / 2);
        cout << n*(n+1)*(2*n+1)/6 + (k-n*(n+1)/2)*(n+1);
        //            情况1       +     情况2
        return 0;
    }
    

    嗯,这些都是数竞牲要会的最基础的东西( )

  • 1
    @ 2023-07-07 14:07:21
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    int main ()
    {
    
    
        int n,s=0,t=0;
        cin>>n;
        for(int i=1;;i++)
        {
            for(int j=1;j<=i;j++){
                s+=i;
                t++;
                if(t==n)
                {
                    cout<<s;
                    return 0;
                }
            }
        }
    
    }
    
  • 1
    @ 2021-08-29 16:46:21
    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int K,N,coin=0;
        scanf("%d",&K);
        for(N=1;K-N>=0;K-=N++)
            coin+=N*N;
        printf("%d\n",coin+K*N);
        return 0;
    }
    
  • 1
    @ 2020-09-22 14:55:24
    #include <cmath>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int n;
        cin >> n;
        int ans = 0;
        for (int i = 1;; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                ans += i;
                if (--n == 0)
                {
                    return cout << ans, 0;
                }
            }
        }
    }
    
  • 1
    @ 2018-09-02 11:48:55

    ***#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int n,k=1;
    int gold=1;
    int day=1;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
    if(day==0){
    k++;
    day=k;
    gold=day;
    }
    ans+=gold;
    day--;

    }
    cout<<ans;
    return 0;
    }*

  • 1
    @ 2018-08-01 22:21:40

    水。。。。一次通过
    var
    i,a,b,n,q:longint;
    begin
    read(n);
    i:=0;
    repeat
    a:=0;i:=i+1;
    repeat
    b:=b+1;
    q:=q+i;
    a:=a+1;
    until (a=i)or(b=n);
    until b>=n;
    writeln(q);
    end.

  • 1
    @ 2018-07-25 20:55:18

    好水的题...
    代码比较丑,
    见谅!

    #include <cstdio>
    using namespace std;
    int main() {
        int k,ans=0,j=1,n=0;
        scanf("%d",&k);
        for (int i=1;i<=k;i++) {
            if (n>=j) {
                j++;
                n=0;
            }
            ans+=j;
            n++;
        }
        printf("%d",ans);
        return 0;
    }
    
  • 1
    @ 2018-06-21 11:59:41

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main()
    {
    int k, days = 1, gold = 0;
    cin>>k;
    while(k > 1)
    {
    int i;
    for(i = 1; i <= days; i++)
    {
    if(k == 0)
    break;
    gold+=days;
    k--;
    }
    days++;
    }
    cout<<gold<<endl;
    return 0;
    }

  • 1
    @ 2017-11-15 15:31:14

    无循环

    #include <stdio.h>
    #include <iostream>
    #include <math.h>

    using namespace std;

    int main()
    {
    int k, n1, sum;

    cin>>k;

    n1 = floor((sqrt(8*k+1)-1)/2);

    sum = (n1*(n1+1)*(2*n1+1)) / 6 + (k-n1*(n1+1)/2)*(n1+1);

    cout<<sum;
    }

  • 1
    @ 2017-09-21 21:10:26

    #include<iostream>
    using namespace std;
    int main()
    {
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int k,i,j,ans=0,a=0;
    cin>>k;
    for(i=1;i<k;i++)
    for(j=1;j<=i;j++)
    {
    ans+=i;
    a++;
    if(a==k)
    {
    cout<<ans;
    return 0;
    }
    }
    cout<<ans;
    return 0;
    }

  • 1
    @ 2017-08-22 02:32:56

    so water

    #include <iostream>
    
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
    
    int main(int argc, char** argv) {
        long long a=1,b=1,n,i,money=0;
        scanf("%lld",&n);
        for(i=1;i<=n;i++)
        {
            if(i>b)
            {
                a++;
                b=b+a;
            }
            money=money+a;
        }
        printf("%lld",money);
        return 0;
    }
    
  • 1
    @ 2017-05-20 16:30:44

    so easy~

    var
      k, i, s:longint;
    begin
      read(k);
      i:=1;
      s:=0;
      while k>=i do begin
        dec(k, i);
        inc(s, sqr(i));
        inc(i)
      end;
      inc(s, i*k);
      write(s)
    end.
    
    
  • 0
    @ 2020-05-22 20:56:45
    #include <bits/stdc++.h>
    using namespace std;
    int money;
    int main()
    {
        //金币
        int K,day,i=1;
        scanf("%d",&K);
        while(money<K)
        {
            day+=i*i;
            money+=i;
            i++;
        }
        if (money==K) printf("%d",day);
        else
        {
            day-=(money-K)*(i-1);
            printf("%d",day);
        }
    }
    
  • 0
    @ 2018-11-07 14:26:19

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int day,i,j,sum=0,s=0;
    cin>>day;
    for(i=1;s<day;i++)
    s+=i;
    for(j=1;j<i-1;j++)
    sum=j*j+sum;
    sum+=(i-1)*(day-s+i-1);
    cout<<sum;
    return 0;
    }

  • 0
    @ 2018-11-04 11:13:09

    Pascal代码
    var
    n,k,i,m,s:longint;
    begin
    readln(n);
    k:=1;
    for i:=1 to n do
    begin
    s:=s+k;
    inc(m);
    if m=k then
    begin
    m:=0;
    inc(k);
    end;
    end;
    write(s);
    end.

  • 0
    @ 2018-08-30 11:28:13

    #include <stdio.h>
    using namespace std;
    int main()
    {
    int k,ans=0,b;
    scanf("%d",&k);
    int a=k;
    for(int i=1;i<=a;i++)
    {
    if(k-i>=0)
    {
    k-=i;
    ans=ans+i*i;;
    }
    else
    {
    b=i;
    i=a+1;
    }
    }
    ans=ans+b*k;
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2017-10-04 00:14:21

    公式无敌。
    #include <iostream>
    using namespace std;

    int k;
    int temp=0;

    int main(){
    cin>>k;
    int i=0;
    while((i*(i+1)/2)<k){
    i++;
    }i--;
    temp+=(k-(i*(i+1)/2))*(i+1);
    temp+=i*(i+1)*(2*i+1)/6;
    cout<<temp;
    return 0;
    }

  • 0
    @ 2017-09-12 21:52:54

    #include <stdio.h>

    int main(){
    int k, i, j,t=0, sum=0;
    int m[10001] = { 0 };
    scanf("%d", &k);
    for (i = 1; i <= k; i++){
    for (j = 1; j <= i; j++){
    if (t==k){
    break;
    }
    else{
    ++t;
    m[t] = i;
    }

    }
    sum += m[i];
    }
    printf("%d\n", sum);
    return 0;
    }

信息

ID
1974
难度
3
分类
模拟 点击显示
标签
递交数
2947
已通过
1418
通过率
48%
被复制
32
上传者