Starters 85- CodeChef

Although this was a fairly good contest in terms of the rank I got, but I think I should have been able to complete atleast 2 more problems, maybe I should have focussed on the Bomb Blast one from beforehand only instead of going for Trip Tastic, in which I got some really messy bug that I wasn't able to fix till the end of the Contest, well, the bomb blast problem was like that one which looks cryptic but was really interesting and should have gone for that. 

Well, with this Problem I moved to the Division 2 of CodeChef but I think that I need a hell lot of practice and will be working on more of such problems.

The Problems that I solved in the Contest are mentioned below with their Explanations and Codes ;)

Crazy Bishops on ChessBoard:-

Code Implementation:-

for _ in range(int(input())):
    n=int(input())
    if(n<=2):
        print(0)
        continue
    if(n<=3):
        print(2)
        continue
    s1=(n//2)+1
    s2=(n- ((n//2)+1))*2
    print(s1+s2-2)

Explanation:-

This, problem is just based on observation when we imagine the chess board like mentioned in the Problem Statement then it's just that we would observe the first 2 mentioned if statements, and for the rest of the code the logic is that apart from the first 3 bishops, the rest bishops are handled in such a way.... just take 1 bishop in the diagonal where they should be and take it to any infinite position so it gives rest of the bishops the space to reside( this took 2 moves ) and the next bishop will go to the diagonal in just 1 move, means the bishops in the lower squares are gonna take 2 moves and the rest will take 1 move, that's the main logic so we divide the bishops in 2 parts ( the ones taking 1move and the ones taking 2 moves ) the one movers are (n//2)+1 bcz the 2nd bishop is already at the diagonal, so that's a corner case i figured, the rest bishops will be n-(1move bishops) and this count is multiplied to 2.


Efficient Pan Linking:-

Code Implementation:-

for _ in range(int(input())):
    n=int(input())
    print(n-((n//20)*20))

Explanation:-

Simply, we had to understand that if each officer can attend only equal no. of applicants so means we have to divide n by 20 to get the number of applicants that each officer entertains, now we just multiply this with 20 to get the number of applicants that 20 officers entertain, so at last we just have to get the number of applicants that don't get entertained, and that will be n- this number that we calculated.


Inside the Stadium:-

Code Implementation:-
for _ in range(int(input())):
    n=int(input())
    runs=list(map(int,input().split()))
    sums=0
    count=0
    for i in range(n):
        sums+=runs[i]
        if(sums==i+1):
            count+=1
           
    print(count)

Explanation:-

We just have to see how many times the runs become equal to the no. of balls played( that in this case is i ) and just increase the count variable whenever it is like this, the sums variable will keep storing the values(runs).


Can Chef:-

Code Implementation:-

for _ in range(int(input())):
    x,y=map(int,input().split())
    dist=2*y
    if(dist<=(x*15)):
        print("YES")
    else:
        print("NO")

Explanation:-

Simply, we just have to get the distance that we can cover with X litres of petrol, that is--> 15X, now we just have to check if this is >= 2Y(The distance we gotta cover).

Comments

Popular Posts