We'd like to thank you all for participating in the contest, and hope you enjoyed it. Hope to see you again soon!
Author: JainWinn
It is given that $$$a$$$ and $$$b$$$ are number of commuters at concourse and platform respectively and $$$c$$$ is maximum capacity of lift .
- Number of non-empty translations from concourse to platform is given by $$${up=(a+c-1)/c}$$$ .
- Number of non-empty translations from platform to concourse is given by $$${down=(b+c-1)/c}$$$ .
- If $$${up \gt down}$$$ ,then answer is $$${2*up-1}$$$ , else answer is $$${2*down}$$$.
#include<bits/stdc++.h>
using namespace std;
void solve(){
int a,b,c;
cin>>a>>b>>c;
int up=(a+(c-1))/c;
int down=(b+(c-1))/c;
if(up>down){
cout<<2*(up)-1<<endl;
}
else{
cout<<2*(down)<<endl;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Author: prathamtyagii
We have to find the minimum number of matchdays for which we can guarantee a winner in an ideal scenario if $$$n$$$ teams are there in the league.Let us take this matchday to be $$$i$$$. To consider the ideal scenario, we need one team that will win all of its matches up to $$$i$$$ matchdays and all the remaining teams draw their matches while facing each other. Now we need to create a gap between the $$$1^{st}$$$ and $$$2^{nd}$$$ team which cannot be surpassed even if the $$$1^{st}$$$ team loses all of its remaining matches and the $$$2^{nd}$$$ team wins all of its remaining matches after $$$i$$$ matchdays. To do this we can directly formulate a condition, $$$3*i \gt i+3*(n-1-i)$$$ where:
$$$3*i$$$ is the final score of the $$$1^{st}$$$ team after winning first $$$i$$$ matchdays and losing the remaining ones
$$$i$$$ is the score of the $$$2^{nd}$$$ team after drawing the first $$$i$$$ matchdays and $$$3*(n-1-i)$$$ is the score after winning the remaining matchdays.
Simplifying the expression, the final condition is $$$i \gt (3*n-3)/5$$$.
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class cfct
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int t = Integer.parseInt(line.split(" ")[0]);
while(t>0){
t--;
String line1 = br.readLine();
int n = Integer.parseInt(line1.split(" ")[0]);
int ans=(3*n-3)/5;
System.out.println(ans+1);
}
}
}
Author: C0de_Beast
We have to convert an hidden number $$$x$$$ into a given number $$$k$$$ with in $$$31$$$ queries, where $$$x$$$ and $$$k$$$ both lies in range $$$[1,10^9]$$$, which can be represented in $$$30$$$ bits.
Our last move will obviously be to convert the hidden number to $$$k$$$, thus we will have to figure out the hidden number in $$$30$$$ queries. We can do by doing the following steps:-
- First we query "? $$$0$$$" to find the number of set bits in the hidden number.
- For every bit from $$$1st$$$ bit to $$$29th$$$ bit from right we can query a number with $$$ith$$$ bit set to find whether it was set in the hidden number or not, while accounting for the fact that this operation would flip the $$$ith$$$ bit.
- Now we want to find the state $$$30th$$$ bit which can we can infer from the initial count of set bits and the count we found during $$$29$$$ queries in $$$2nd$$$ step.
After these $$$30$$$ queries we will be able to construct the current hidden number $$$x$$$ and just query "? $$$x⊕k$$$" to finally convert the hidden number to $$$k$$$.
#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--) {
int k;
scanf("%d", &k);
int set_bits;
printf("? %d\n", 0);
fflush(stdout);
scanf("%d", &set_bits);
int set_bits_t = set_bits;
int set_bits_c{};
int p{};
for(int x = 0; x < 29; x++) {
printf("? %d\n", 1<<x);
fflush(stdout);
int temp;
scanf("%d", &temp);
if(temp == -1) {
return 0;
}
if(temp > set_bits) {
p = p|(1<<x);
}else {
set_bits_c++;
}
set_bits = temp;
}
if(set_bits_c != set_bits_t) {
p = p|(1<<29);
}
p = p^k;
printf("? %d\n", p);
fflush(stdout);
int temp;
scanf("%d", &temp);
if(temp == -1) {
return 0;
}
printf("!\n");
fflush(stdout);
}
return 0;
}



