Click the Twitter icon to follow our tweets and
know more about us.

Showing posts with label Easy. Show all posts
Showing posts with label Easy. Show all posts

The battle near the swamp

0

The battle near the swamp 

Time limit: 1 second 
Memory limit: 64 MB 
____________________________________________________________________________

Gungan: Jar Jar, usen da booma! 
Jar Jar: What? Mesa no have a booma! 
Gungan: Here. Taken dis one. 
_________________________________________________________________________________
In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to provide their army in order to get the droids of the Federation out from the capital. The gungan ruler Boss Nass was so grateful for uniting the nations that he appointed Jar Jar a general. 

And here they are: two armies lined up along the bank of the swamp. The droids of the Federation are well-disciplined soldiers. They stand in neat formation, divided into 𝑛 blocks of 𝑘 droids each. The gungans have a foolproof weapon against droids, which is small energy balls called boom booms. One such ball can disable exactly one droid.

Jar Jar Binks also decided to split his army into 𝑛 parts and give each part a task to destroy the corresponding block of droids. Each part received a truck with boom booms. Now help general Binks calculate the number of boom booms that will be left unused and the number of droids that will survive the attack. You can assume that when a boom boom is fired at a droid by a gungan, it always hits the target. 

Input 
The first line of the input contains numbers 𝑛 and 𝑘 (1 ≤ 𝑛, 𝑘 ≤ 10 000). The second line contains 𝑛 numbers 𝑎𝑖 (0 ≤ 𝑎𝑖 ≤ 100 000) — the number of boom-booms in the 𝑖-th truck.

Output
Print two integers — the number of unused boom booms and the number of survived droids.


CODE in JAVA:

import java.io.*;

public class boomboom{
 public static void main(String []args)throws IOException{
  
  BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
   int[] j= new int[2],n;
   
    String[] s2 = inp.readLine().split(" ");
    j[0]=Integer.parseInt(s2[0]);
    j[1]=Integer.parseInt(s2[1]);
    
   
            int[] m= new int[j[0]];int c=0,k=0;
          
            String[] s1 = inp.readLine().split(" ");
           for(int i=0;i<j[0];i++)
              m[i]=Integer.parseInt(s1[i]);
            
            
            
            for(int l=0;l<j[0];l++){
             int a=j[1]-m[l];
             if(a>=0)
              k=k+a;
             else
              c=c-a;
             
            }
            System.out.println(c+"  "+k);
       }
       
       
    }
    

inc ARG

0

inc ARG

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit.
Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded.
Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell.
The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.

Output
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
Examples
input
4
1100
output
3
input
4
1111
output
4
Note
In the first sample the cell ends up with value 0010, in the second sample — with 0000.

CODE in JAVA:

import java.io.*; 
import java.util.*; 
public class incarg{ 
    public static void main(String args[]) throws IOException {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
         int a = Integer.parseInt (br.readLine()),c=0; 
         String str = br.readLine();
         if(str.length()==a){
            for(int i=0;i<str.length();i++){
                char d = str.charAt(i);
                if(d == '1')
                    c++;
                else{
                    c++;
                    break;}
                }
                System.out.println(c);
            }
         }
    }

~Please leave your questions in the comments~


Way Too Long Words

0

Way Too Long Words


time limit per test :
2 seconds

memory limit per test : 
256 megabytes

input: 
standard input

output: 
standard output
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
Examples
input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
output
word
l10n
i18n
p43s
CODE in JAVA:
import java.io.*; 
import java.util.*; 
public class Watermelon{
 public static void main(String args[])throws IOException{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
 int n = Integer.parseInt(br.readLine());
 String word;
 for(int i=0; i<n; i++)
 { word = br.readLine();
  if(word.length() > 10){
  System.out.println(word.charAt(0)+""+(word.length()-2)+""+
                      word.charAt(word.length()-1));
  }
  else
   System.out.println(word);
 }
}
}

~Please leave your questions in the comments~

Watermelon

0

Watermelon


time limit per test :1 second
memory limit per test : 64 megabytes
input : standard input
output : standard output
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

Input
The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Output
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Examples
input
8
output
YES
Note
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).


CODE in JAVA:

import java.io.*; 
import java.util.*; 
public class Watermelon{
 public static void main(String args[]){
 Scanner in = new Scanner(System.in);
 int w = in.nextInt();
 if(w%2==0 && w!=2)
  System.out.println("YES");
 else
  System.out.println("NO");
}
}

~Please leave your questions in the comments~



Theatre Square

0

Theatre Square

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input
The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).
Output
Write the needed number of flagstones.
Examples
input
6 6 4
output
4
Code in JAVA:

import java.io.*; 
import java.util.*; 
public class Watermelon{
 public static void main(String args[]){
 Scanner in = new Scanner(System.in);
 long m = in.nextLong();
 long n = in.nextLong();
 long a = in.nextLong();
 long x = m;
 long y = n;
 if(m%a!=0 && a!=1)
  x=a*((m/a)+1);
 if(n%a!=0 && a!=1)
  y=a*((n/a)+1);
 System.out.println((x*y)/(a*a));
}
}