当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
xss的DOMPurify过滤框架:一个循环问题以及两个循环问题
Janus actual production case
【二叉树-中等】687. 最长同值路径
【Kali安全渗透测试实践教程】第7章 权限提升
OpenCV图像处理学习一,加载显示修改保存图像相关函数
【每日一题】1413. 逐步求和得到正数的最小值
The 25th day of the special assault version of the sword offer
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
ArcGIS Advanced (1) - Install ArcGIS Enterprise and create an sde library
2022.8.9考试排列变换--1200题解
浅写一个下拉刷新组件
【Kali安全渗透测试实践教程】第6章 密码攻击
2022.8.9 Exam Travel Summary
what is a microcontroller or mcu
LeetCode每日两题02:两数之和 II - 输入有序数组 (均1200道)
MySQL:你做过哪些MySQL的优化?
OpenCV图像处理学习四,像素的读写操作和图像反差函数操作
GDB之指令基础参数
官宣出自己的博客了
华为HCIE云计算之FC添加ipsan数据存储