当前位置:网站首页>【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;
}
边栏推荐
- First day of database
- LEARNING TARGET-ORIENTED DUAL ATTENTION FOR ROBUST RGB-T TRACKING
- Summary and review
- Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation
- 二、用户登录和注册
- Object. Specific implementation and difference between create() and new
- Set center alignment
- 模块化笔记
- Modular notes
- 1、 Sqlserver2008 installation (with password), database creation, C form project test
猜你喜欢
随机推荐
【LeetCode】-- 17.电话号码的字母组合
337. house raiding III
VTK vtkplane and vtkcutter use
二、用户登录和注册
First day of database
Shuttle inside and outside margins
【迅为干货】龙芯2k1000开发板opencv 测试
webserver
MS office level II wrong question record [6]
Education expert wangzhongze shared his experience for many years: family education is not a vassal
微信小程序开发(原生和uniapp)DOM标签对比介绍
服务器调参实录
Heartless sword Chinese English bilingual poem 001 Love
Atom, the top stream editor, will leave the historical stage on December 15
MS office level II wrong question record [4]
Concurrent tool class
Interview question 17.08 Circus tower
Cross-Modal Pattern-Propagation for RGB-T Tracking
The difference between arrow function and ordinary function
Oracle pl/sql these query results cannot be updated. Please include ROWID or use Select For update
![[并发进阶]——线程池总结](/img/69/dc8146dafc30f8a8efa012b67aa05c.png)



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




