当前位置:网站首页>【CF#654 (Div. 2)】A. Magical Sticks
【CF#654 (Div. 2)】A. Magical Sticks
2022-06-11 07:10:00 【percation】
The question , Give an integer n, Description yes n A stick ( Length from 1,2,… , Until n)
Every two sticks can be combined into a new stick , This new stick can be used to continue merging
Find the maximum number of sticks of the same length
Ideas : The first thing to think about is the sum of the arithmetic sequence
later , Observe if you want to ( A stick of the same length ) The most , The length is n My stick , You can't merge if you want to stay .
Less than n Those sticks , from 1 To n-1, Conduct 1+n-1, 2 + n- 2,…, Go down in turn
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1e2 + 10;
int a[N],b[N];
int ans;
int t;
ll n;
int main()
{
cin >> t;
while(t--){
cin >> n;
if(n%2 || n == 2){
ans = 1 + (n - 1)/2;
}
else{
ans = 1 + (n - 1)/2;
}
cout << ans << endl;
}
return 0;
}
Code can be , Further equivalent substitution .
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1e2 + 10;
int a[N],b[N];
int ans;
int t;
ll n;
int main()
{
cin >> t;
while(t--){
cin >> n;
ans = 1 + (n - 1)/2;
cout << ans << endl;
}
return 0;
}
边栏推荐
- Records how cookies are carried in cross domain requests
- 资深OpenStacker - 彭博、Vexxhost升级为OpenInfra基金会黄金成员
- Web API、DOM
- Interview question 17.08 Circus tower
- 通过 Ingress 进行灰度发布
- saltstack部署zabbix状态文件编写
- Common modules of saltstack
- Latex various arrows / arrows with text labels / variable length arrows
- Interview question 02.06 Palindrome linked list
- Leetcode-9.Palindrome Numbber
猜你喜欢

matplotlib的cmap

Education expert wangzhongze shared his experience for many years: family education is not a vassal

Drawing with qpainter

WPF data binding (IV)
![[deploy private warehouse based on harbor] 4 push image to harbor](/img/af/8e28b229d94f3e6eab02308b69dc74.jpg)
[deploy private warehouse based on harbor] 4 push image to harbor

Saltstack deployment LNMP

模块化笔记

Common troubleshooting tools and analysis artifacts are worth collecting
![Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])](/img/1c/4013479ce1fc5b0ff2ebeb754f05a9.png)
Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])

Analysis of key points and difficulties of ES6 promise source code
随机推荐
@JsonProperty注解
Transformer Tracking
P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
1269. number of options left in place
河南高考VS天津高考(2008年-2021年)
WPF 数据绑定(四)
[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]
WPF data binding (IV)
Promise. All capture error
. Net C Foundation (6): namespace - scope with name
1190. invert the substring between each pair of parentheses
P3811 [template] multiplicative inverse
Leetcode-104. Maximum Depth of Binary Tree
webserver
pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
Phi and phi (Mobius inversion + formula)
Explain the difference between void 0 and undefined
Leetcode-141. Linked List Cycle
AtomicInteger原子操作类
Stack -- one of two common linear structures of linear structure