Saturday, 16 May 2020

Codeforces Round #643 (Div. 2) : Young Explorers :solution in python

B. Young Explorers


time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties...

Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter

 — his inexperience. Russell decided that an explorer with inexperience can only join the group of

or more people.

Now Russell needs to figure out how many groups he can organize. It's not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.

Input

The first line contains the number of independent test cases

(). Next

lines contain description of test cases.

The first line of description of each test case contains the number of young explorers

(

).

The second line contains

integers (), where is the inexperience of the

-th explorer.

It's guaranteed that sum of all

doesn't exceed

.

Output

Print

numbers, each number on a separate line.

In

-th line print the maximum number of groups Russell can form in

-th test case.

Example
Input
Copy
2
3
1 1 1
5
2 3 1 2 2
Output
Copy
3
2
Note

In the first example we can organize three groups. There will be only one explorer in each group. It's correct because inexperience of each explorer equals to

, so it's not less than the size of his group.

In the second example we can organize two groups. Explorers with inexperience

, and will form the first group, and the other two explorers with inexperience equal to

will form the second group.

This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to

, and the second group using only one explorer with inexperience equal to . In this case the young explorer with inexperience equal to will not be included in any group.





Solution in Python :

t = int(input())
ar = []
for i in range(t) :
    n = int(input())
    e = [int(i) for i in input().split()]
    e.sort()
    mul = 0 ; count = 0 ; count1 = 1 ; sumif = 0 ;sumelse = 0
    for i in e:
        if i == 1 :
            count += 1
        else :
            if mul <count1**2 :
                if count1 == 1:
                    mul = 1
                mul *= i
                count1 += 1
                sumif += 1
            else :
                count1 = 1
                mul = 0
                count += 1
                sumelse += 1
    if sumif <sumelse :
        count -= 1
    elif sumif >sumelse :
        count += 1
    ar.append(count)
for i in ar :
    print(i)

Monday, 27 April 2020

Note : some modification required !! Hackerearth Byteland Problem : Solution in python

 PROBLEM STATEMENT
Points: 50
In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit).
You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. You have one gold coin. What is the maximum amount of American dollars you can get for it?
Input The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.
Output For each test case output a single line, containing the maximum amount of American dollars you can make.
Explanation You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. It is better just to change the 2 coin directly into $2.
SAMPLE INPUT
 
12
2

SAMPLE OUTPUT
 
13
2

Time Limit: 9.0 sec(s) for all input files combined.


Solution in python :





list1 = []
while True :
    try :
        n = input()
        if n :
            count = 0
            n = int(n)
            count+=int(n/2)+int(n/3)+int(n/4)
            if n>count :
               count = n
            list1.append(count)
    except EOFError :
           break
for i in list1 :
    print(i) 

Hackerearth : checking horizontal and vertical symmetric matrix : Solution in python

PROBLEM STATEMENT
Points: 30
You are given a square matrix of size n. Rows are indexed 1 to n from top to bottom and columns are indexed 1 to n form left to right. Matrix consists of only '*' and '.'. You need to check whether matrix is symmetric or not. if it is, check it is symmetric about vertical axis or horizontal axis or both.
A matrix is said to be symmetric about horizontal axis if 1st row is identical to nth row, 2nd is identical to (n−1)th row and so on...
A matrix is said to be symmetric about vertical axis if 1st column is identical to nth column, 2nd identical to (n−1)th and so on for all columns.
INPUT :
First line contains t,the number of test cases. First line of each test case contains n the size of matrix. Each of next n lines contain n characters.
OUTPUT:
Output t lines, answer for each test case. Print "HORIZONTAL" if symmetric about horizontal axis. Print "VERTICAL" if symmetric about vertical axis. Print "BOTH" if symmetric about both axes. print "NO" if it is not symmetric.
Constraints :
1<t≤500
1<n<50
SAMPLE INPUT
 
3
4
*.*.
.*.*
*.*.
.*.*
3
.*.
*.*
.*.
3
..*
**.
..*


SAMPLE OUTPUT
 
NO
BOTH
HORIZONTAL

Solution in python:

list2 = []
t = int(input())
for i in range(t) :
    list1 = []
    count = 0 
    count2 = 0
    n  = int(input())
    for j in range(0,n) :
        list1.append(input().split([0])
    for k in range(0,n) :
        if list1[0+k] != list1[n-1-k] :
            count = 0
            break 
        else : 
            count=1

    for j in range(n) :
        for k in range(n) :
                if list1[0+k][0+j] != list1[0+k][n-1-j] :
                    count2 = 0
                    break 
                else : 
                    count2 = 1
    if count==0 and count2==0 :
        list2.append('NO')
    elif count==0 and count2 :
        list2.append('VERTICAL')
    elif count and count2 == 0 :
         list2.append('HORIZONTAL')
    else :
         list2.append('BOTH')
for i in list2 :
    print(i)