当前位置:网站首页>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;
}
边栏推荐
- Golang nil的妙用
- 免费文档翻译软件电脑版软件
- HRnet
- 翻译工具-翻译工具下载批量自动一键翻译免费
- In automated testing, test data is separated from scripts and parameterized methods
- 【机器学习】随机森林、AdaBoost、GBDT、XGBoost从零开始理解
- 《GB39707-2020》PDF download
- openpose脚部标注问题梳理
- The 25th day of the special assault version of the sword offer
- LeetCode 每日一题——1413. 逐步求和得到正数的最小值
猜你喜欢
随机推荐
[Swoole Series 3.5] Process Pool and Process Manager
2022年8月1日-8月7日(本周10小时,合计1422小时,剩余8578小时)
2022.8.8考试区域链接(district)题解
桌面云组件介绍与安装
2022.8.8考试摄像师老马(photographer)题解
2022.8.8考试从记忆中写入(memory)题解
OpenCV图像处理学习二,图像掩膜处理
数据库治理利器:动态读写分离
【SSRF漏洞】实战演示 超详细讲解
Maya制作赛博朋克机器人模型
【二叉树-中等】687. 最长同值路径
2022.8.9 Remainder of Exam Balance--1000 Question Solutions
2022.8.9考试平衡的余数--1000题解
剑指offer专项突击版第25天
what is a microcontroller or mcu
【Kali安全渗透测试实践教程】第6章 密码攻击
论旅行之收获
C# winform 单选框
Open3D 中点细分(网格细分)
On the Harvest of Travel