当前位置:网站首页>2022.8.8 exam sweeps the horse (sweeper) antithesis
2022.8.8 exam sweeps the horse (sweeper) antithesis
2022-08-10 03:22:00 【bj_hacker】
题目
3、Cleaner old horse(sweeper)–900
时间限制: | 空间限制:
题目描述:
有 个自然数 .
Find out how many times you have done it at least ,An operation includes the following steps:
1.选择两个整数 满足 ,且 ;
2.将 修改为 ;
3.将 修改为 .
共 组测试数据.
输入格式:
第一行仅有一个正整数 ( ),表示测试数据的组数.
接下来有 组测试数据:
第一行有一个正整数 ( ,且所有测试数据中 之和不超过 );
第二行为 个整数 ( ).
输出格式:
对于每组测试数据,输出一行一个整数,表示至少多少次操作(可以为0).
思路
The idea is to build a bridge,0Use one to make up for it,All greater than0to add,第一个非0after counting0算作1去相加 搭桥 {搭桥} 搭桥,不算最后一个.
重点
ans最大为2*105*109= 2 * 1014
要开long long
代码实现
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+10;
int t,n;
ll ans;
int a[maxn];
int main(){
scanf("%d",&t);
while(t--){
ans=0;
bool flag=false;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(i==n)break;
if(a[i]){
ans+=a[i];
flag=true;
}
else {
if(flag)ans++;
else continue;
}
}
printf("%lld\n",ans);
}
return 0;
}
边栏推荐
- mysql -sql编程
- 数据库治理利器:动态读写分离
- FusionConpute虚拟机的发放与管理
- MySQL:日志系统介绍 | 错误日志 | 查询日志 | 二进制日志:bin-log数据恢复实践 | 慢日志查询
- 【二叉树-中等】1261. 在受污染的二叉树中查找元素
- RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
- 《GB39732-2020》PDF下载
- The 25th day of the special assault version of the sword offer
- 781. 森林中的兔子
- xss的DOMPurify过滤框架:一个循环问题以及两个循环问题
猜你喜欢
随机推荐
常用正则备查
官宣出自己的博客啦
Janus actual production case
【二叉树-简单】112. 路径总和
【论文粗读】(NeurIPS 2020) SwAV:对比聚类结果的无监督视觉特征学习
2022.8.9考试立方和--1100题解
论旅行之收获
【二叉树-中等】1104. 二叉树寻路
liunx PS1 设置
2022强网杯 Quals Reverse 部分writeup
LeetCode 每日一题——1413. 逐步求和得到正数的最小值
【二叉树-困难】124. 二叉树中的最大路径和
3dmax如何制作模型走路动画
LeetCode每日两题02:两数之和 II - 输入有序数组 (均1200道)
Fusion Compute网络虚拟化
2022.8.8考试区域链接(district)题解
UXDB现在支持函数索引吗?
MySQL:你做过哪些MySQL的优化?
Shell编程--awk
JCMsuite—单模光纤传播模式









