MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Numbers on Whiteboard/solution.cpp:8–33  ·  view source on GitHub ↗

here the round up of 2.5 is 3 so the average of 1 to n will be 2 only. Here we can start from n to 1 and take average of current and average of previous operation So here we used stack to make it easy We pop last two elements and push the average into same stack contains only one element

Source from the content-addressed store, hash-verified

6//So here we used stack to make it easy
7//We pop last two elements and push the average into same stack contains only one element
8int main()
9{
10 ios_base::sync_with_stdio(0);
11 cin.tie(0); cout.tie(0);
12 int t;
13 cin>>t;
14 while(t--){
15 int n;
16 cin>>n;
17 stack<int>arr;
18 for(int i=0;i<n;i++){
19 arr.push(i+1);
20 }
21 cout<<2<<endl;
22 while(arr.size()>1){
23 int a = arr.top();
24 arr.pop();
25 int b = arr.top();
26 arr.pop();
27 cout<<a<<" "<<b<<endl;
28 //round is eg. 2.5 is 3
29 arr.push(ceil((float)(a+b)/2));
30 }
31 }
32 return 0;
33}
34
35

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected