当前位置:网站首页>十九届浙大城院程序设计竞赛 F.Sum of Numerators(数学/找规律)
十九届浙大城院程序设计竞赛 F.Sum of Numerators(数学/找规律)
2022-08-01 13:48:00 【Curz酥】
题目链接 https://ac.nowcoder.com/acm/contest/31533/F
![]()
示例1
输入
2 5 0 5 1输出
15 12
解析:
数学思维题。枚举结果来找规律,然后利用等差数列求和公式来求出结果。
C++代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int t, n, k, res;
cin >> t;
while(t--){
cin >> n >> k;
res = n * (n + 1) / 2; //先用等差数列求和公式求出总和
while(n and k){
n /= 2; //会被约分的数字个数每次都是总长的一半
--k; //每次被约分,2的次数减一
res -= (n * (n + 1) / 2); //找规律,可知每次被约分掉的总和是 等差数列求1到被约分掉的数字个数之和
}
cout << res << "\n";
}
return 0;
}
边栏推荐
- ABC260 E - At Least One (Dual Pointer)
- windows IDEA + PHP+xdebug 断点调试
- D - Draw Your Cards(模拟)
- mysql的基本使用
- 论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
- 使用ffmpeg来查看视频的信息,fps,和width,height
- JMP Pro 16.0软件安装包下载及安装教程
- A Beginner's Guide to Performance Testing
- [LiteratureReview]Optimal and Robust Category-level Perception: Object Pose and Shape Estimation f
- 高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能
猜你喜欢
随机推荐
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
为什么最大值加一等于最小值
线上问题排查常用命令,总结太全了,建议收藏!!
安全又省钱,“15岁”老小区用上管道燃气
观察者模式
formatdatetime function mysql (date sub function)
[机缘参悟-57]:《素书》-4-修身养志[本德宗道章第四]
让程序员早点下班的效率工具
10年稳定性保障经验总结,故障复盘要回答哪三大关键问题?|TakinTalks大咖分享
How does the SAP ABAP OData service support the Create operation trial version
SAP ABAP OData 服务如何支持创建(Create)操作试读版
iframe tag attribute description detailed [easy to understand]
Why does the maximum plus one equal the minimum
快速理解拉格朗日乘子法
响应式2022英文企业官网源码,感觉挺有创意的
tensorflow2.0手写数字识别(tensorflow手写体识别)
Data Mining-04
Six Stones Programming: Problems must be faced, methods must be skillful, and functions that cannot be done well must be solved
牛客刷SQL--6
RGB系列开发稳定响应快速灯带拾音灯氛围灯等应用定制方案










