题解 | #[NOIP2015]金币#

[NOIP2015]金币

https://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int money=1;//当天金币
        int sum=0;//统计总金币
        int count=1;//应得某金币次数
        int tmp=1;//记录当天应得的金币数量
        for(int i=1;i<=n;i++){
            if(count==0){
                count=++tmp;
                money=count;
            }
            sum+=money;
            count--;
        }
        System.out.println(sum);
    }
}

全部评论

相关推荐

牛客40297450...:不是研究生强,是你强
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务