当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
what is a microcontroller or mcu
Deep Learning (5) CNN Convolutional Neural Network
QT模态对话框及非模态对话框学习
实操|风控模型中常用的这三种预测方法与多分类场景的实现
c# 解决CS8602告警 解引用可能出现空引用
openpose脚部标注问题梳理
【每日一题】1413. 逐步求和得到正数的最小值
2022.8.9 Exam Travel Summary
2022.8.9考试游记总结
Screen 拆分屏幕
2022年8月1日-8月7日(本周10小时,合计1422小时,剩余8578小时)
【SSRF漏洞】实战演示 超详细讲解
SQL注入的order by ,limit与宽字节注入
RESOURCE_EXHAUSTED: etcdserver: mvcc: database space exceeded
【机器学习】随机森林、AdaBoost、GBDT、XGBoost从零开始理解
OpenCV图像处理学习二,图像掩膜处理
剑指offer专项突击版第25天
Process management and task management
Fusion Compute网络虚拟化
【Kali安全渗透测试实践教程】第8章 Web渗透









