PROBLEM LINK:
Setter: Utkarsh Gupta
Tester: Aryan Chaudhary
Editorialist: Rishabh Gupta
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef is playing badminton today. The service rules of this singles game of badminton is as follows:
- The player who starts the match serves from right side of their court.
- If the server has won an even number of points during a game, then they shall serve from the right side of the service court for the subsequent point.
Chef will be the player who begins the match.
Given the number of points P, obtained by Chef at the end of the game, please determine how many times did the Chef serve from right side of the court.
EXPLANATION:
For each of the even number less than or equal to P, chef gets to serve once. And the total even numbers \leq P are \lfloor P/2 \rfloor + 1.
TIME COMPLEXITY:
O(1) for each test case.
SOLUTION:
Setter's Solution
#include<iostream>
int main(){
int n,t; std::cin>>t; while(t--){
std::cin>>n;
std::cout<<(n/2)+1<<'\n';
}
return 0;
}
Editorialist's Solution
#include<bits/stdc++.h>
#define ll long long
using namespace std ;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt" , "r" , stdin) ;
freopen("output.txt" , "w" , stdout) ;
#endif
int t;
cin >> t ;
while(t--){
int n;
cin>>n;
cout<<1 + n/2<<endl ;
}
return 0;
}