当前位置:网站首页>【CF#654 (Div. 2)】A. Magical Sticks

【CF#654 (Div. 2)】A. Magical Sticks

2022-06-11 07:10:00 percation

Through the tunnel


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;
}
原网站

版权声明
本文为[percation]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020522591287.html