当前位置:网站首页>Codeforces 1637 C. Andrew and stones - simple thinking
Codeforces 1637 C. Andrew and stones - simple thinking
2022-06-12 13:32:00 【Tianyi City*】
The question :
Here you are. n A pile of stones , You can choose three positions at a time i,j,k(i<j<k). And the current j There must be at least two stones . take j Put a stone in i, Put a stone in j. Ask where you ultimately want all the stones to be 1 perhaps n On , Ask if you can finish , What is the minimum number of steps .
Answer key :
Classification of discussion , We can see that [2,n-1] If all of them are even numbers, then the sum /2 That's the answer. .
What if there are odd numbers ? Then it needs another place to give it a , And then put it in 1 perhaps n On , That is, one step becomes two . If there is no other place for it , Isn't that impossible . So you can get it. : How many odd numbers , Add as many steps as you want . If n=3 perhaps [2,n-1] All values of the position of are 1, It's impossible .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5;
int a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,odd=0;
ll s=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(1<i&&i<n)
odd+=a[i]%2,s+=a[i]/2;
}
if(s==0||(odd&&n==3)){
printf("-1\n");
continue;
}
s+=odd;
printf("%lld\n",s);
}
return 0;
}
边栏推荐
- Script引入CDN链接提示net::ERR_FILE_NOT_FOUND问题
- Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning
- D1 哪吒开发板 了解基本的启动加载流程
- 一种快速创建测试窗口的方法
- view的子视图的递归
- Hudi key generation
- [WUSTCTF2020]颜值成绩查询-1
- imagemagick:a gentle introduction to magick++
- torch_geometric message passing network
- go-zero 微服务实战系列(二、服务拆分)
猜你喜欢

Innovation training (XI) summary of some bugs in the development process

镜像扫描工具预研

Octopus network progress monthly report | may 1-May 31, 2022

Implementing tensorflow deep learning framework similarflow with numpy

The goods are full. You must take this knowledge

一种快速创建测试窗口的方法
![[embedded] serial communication and its case](/img/5c/2e691e5ef03c7d65fd514e8b940e7b.jpg)
[embedded] serial communication and its case

Further understanding of the network

Application of binary search -- finding the square root sqrt of a number

Successfully rated Tencent t3-2, 10000 word parsing
随机推荐
【刷题篇】超级洗衣机
达梦数据库DM8 windows环境安装
LeetCode滑动窗口刷题总结
[cloud native | kubernetes] kubernetes networkpolicy
imagemagick:a gentle introduction to magick++
1001:Hello,World
go-zero 微服务实战系列(二、服务拆分)
Openstack network
[cloud native | kubernetes] learn more about ingress
import torch_geometric 第一个图网络例子
How to solve the problem of data table query error when SQLite writes the registration function?
1005: estimation of the earth's population carrying capacity
Seeking magic square of order n with C language
leetcode 47. Permutations II full permutations II (medium)
torch_ About the geometric Mini batch
m1 pod install pod lint 失败解决方案
static 和 extern 关键字详解
Symbolic constant, const qualifier
AVFoundation
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain