惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
Lohrmann on Cybersecurity
I
Intezer
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
AI
AI
SecWiki News
SecWiki News
C
Cybersecurity and Infrastructure Security Agency CISA
IT之家
IT之家
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
S
Security Affairs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google DeepMind News
Google DeepMind News
H
Hacker News: Front Page
爱范儿
爱范儿
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
V
V2EX
H
Help Net Security
The Hacker News
The Hacker News
G
Google Developers Blog
Latest news
Latest news
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tor Project blog
宝玉的分享
宝玉的分享
博客园 - 司徒正美
H
Heimdal Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
S
SegmentFault 最新的问题
C
Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
B
Blog RSS Feed
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone
L
LINUX DO - 最新话题
K
Kaspersky official blog
MongoDB | Blog
MongoDB | Blog

Ayx 博客

PaperMC 服务器允许刷线机/无头活塞等配置 如何从 YouTube 搬运视频?如何做一个合格的 YouTube 搬运工?我搬运视频的方法与原则 此博客的所有镜像 免费获取在 Microsoft Store 中收费 ¥7.00 的 HEVC 视频扩展 CLI Post Test moefox.tech 已于 7 月 25 日过期,本站域名已更换为 imayx.top 关于 链接 LG V50 ThinQ 韩版 LGU+ 从解锁 BootLoader 到破解 VoLTE / NSA 5G、从刷入第三方 Recovery 到硬格、从混刷到黑砖全教程 Python 3 入门学习笔记 新年快乐 & 本站的改版 在 Hugo 主题 Stack 中轻松配置 Waline 评论系统 出现 error: ld returned 1 exit status 的五种原因以及解决方法 MySSL 安全签章 题解 P1603 斯诺登的密码 安装 Hugo 主题 Stack 时你可能会遇到的问题 独角兽搜索 Hello Hugo 题解 UPC-1488 客户调查(client) 题解 P5707 【深基2.例12】上学迟到 题解 P5719 【深基4.例3】分类平均 分享一下我的博客园在用的修改版 Wider Gao 博客园主题 使用 Node.js(安装Hexo)时出现了 rollbackFailedOptional 错误的解决方法 题解 HDU2063 过山车 题解 YBT 1000:入门测试题目 题解 P1650 田忌赛马 OJ术语的解释: AC、WA、TLE、OLE、MLE、RE、PE、CE、UKE 都是些啥? 归档 搜索 友链
题解 P2669 [NOIP2015 普及组] 金币
2021-05-09 · via Ayx 博客

博客园迁移计划

(题面来自洛谷

题目描述

国王将金币作为工资,发放给忠诚的骑士。第一天,骑士收到一枚金币;之后两天(第二天和第三天),每天收到两枚金币;之后三天(第四、五、六天),每天收到三枚金币;之后四天(第七、八、九、十天),每天收到四枚金币……;这种工资发放模式会一直这样延续下去:当连续 $n$ 天每天收到 $n$ 枚金币后,骑士会在之后的连续 $n+1$ 天里,每天收到 $n+1$ 枚金币。

请计算在前 $k$ 天里,骑士一共获得了多少金币。

输入格式

一个正整数 $k$ ,表示发放金币的天数。

输出格式

一个正整数,即骑士收到的金币数。

输入输出样例

输入 #1

输出 #1

输入 #2

输出 #2

说明/提示

【输入输出样例 1 说明】

骑士第一天收到一枚金币;第二天和第三天,每天收到两枚金币;第四、五、六天,每天收到三枚金币。因此一共收到 $1+2+2+3+3+3=14$ 枚金币。

对于 $100%$ 的数据,$1\le k\le 10^4$

分析

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k,				//发放金币的天数
	    coin   = 0,		        //骑士收到的金币数
	    per    = 1,		        //每天发给骑士的金币数
	    remain = 1;		        //按此数量发放的剩余天数
	cin>>k;
	for(int i=1;i<=k;i++) {
		coin+=per;		//发放金币
		if(--remain==0) 
		  remain=++per;	        //之后的 per+1 天每天发放 per+1 枚金币
	}
	cout<<coin;
	return 0;
}

编辑记录

突然发现之前放的代码压根没法通过编译…

2023-10-28 11:49:00

2021-08-06 18:10:00