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

推荐订阅源

T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
T
Tailwind CSS Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
C
Cybersecurity and Infrastructure Security Agency CISA
O
OpenAI News
Recorded Future
Recorded Future
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
F
Full Disclosure
Recent Announcements
Recent Announcements
Vercel News
Vercel News
S
Schneier on Security
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
B
Blog RSS Feed
宝玉的分享
宝玉的分享
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
N
Netflix TechBlog - Medium
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone

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】上学迟到 题解 P2669 [NOIP2015 普及组] 金币 分享一下我的博客园在用的修改版 Wider Gao 博客园主题 使用 Node.js(安装Hexo)时出现了 rollbackFailedOptional 错误的解决方法 题解 HDU2063 过山车 题解 YBT 1000:入门测试题目 题解 P1650 田忌赛马 OJ术语的解释: AC、WA、TLE、OLE、MLE、RE、PE、CE、UKE 都是些啥? 归档 搜索 友链
题解 P5719 【深基4.例3】分类平均
2021-02-20 · via Ayx 博客

转载自我自己的博客园

这题太有意思了,发个题解纪念一下

题面来自洛谷

$\LaTeX$ 渲染不了,哭了(明明后台预览是可以渲染的啊=

(搬到 Hugo 博客可以正常显示了)

题目描述

给定 $n(n \le 10000)$ 和 $k(k \le 100)$,将从 $1$ 到 $n$ 之间的所有正整数可以分为两类:$A$ 类数可以被 $k$ 整除(也就是说是 $k$ 的倍数),而 $B$ 类数不能。请输出这两类数的平均数,精确到小数点后 $1$ 位,用空格隔开。

数据保证两类数的个数都不会是 $0$。

输入格式

输出格式

输入输出样例

输入 #1

输出 #1

分析

利用了等差数列等高阶数学知识来减少循环次数。

代码(C++)

 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 n,k,can,cant,all,num=0;
	cin>>n>>k;
	all=(n+1)*n/2;
	for(int i=k;i<=n;i+=k){
		can+=i;
		num++;
	}
	cant=all-can;
	double a = (double)can/num;
	double a_ = (double)cant/(n-num);
	printf("%.1lf %.1lf",a,a_);
	return 0;
}

编辑记录

2021-08-13 12:01:00