Friday, January 20, 2012

Traffic Solution

okay


  This is a sample image of how a Chauraha looks like and hence i have devided it in four quadrants however as per the requirement it can be subdivided/coagulated .
in center what you see is square a area what we do not want to consider  and other than that 1/2/3/4 has sensors which are density measuring sensors
Defn of density is
Density=Weight/SQinch

now what these sensors do is they feed data from the circled area to computers and they let teh network learn about the traffic pattern , on that basis we divide the whole traffc 12 hrs say 8-8 in 12 diff zone with diff color codes and ofcourse diff weight as it will translate in to code

now say at any given time section A has 5 bus section B has 11 Cars C has 2 Bus 3 cars and D has only Bikes   
then as per density  feeded by the sensors to the Computer the program will be able to decide that its the section one which needs immediate clearance and it will be synchronized with the  next stop. with +-2 min this is also a way to let people know that they need to get on to public transport system .

Now this arrangement ill fail if the peopel do not follow traffic rules , yes but that probblem can not be solved unless we hire peopel but hell no , thats not the solution, what we need to do is give the power back to Citizen , if i find a Vehicle offending traffic rule at junction what all i need to do is take a pic of vehicle and send it
the Image sending location in 90% of teh cases will be also the source of problem /Plate no May be .

Then the snapshot of vehicle can be taken by CCTV cameras at those chaurahas and Charge can be directly sent through email/Phone message..

Monday, January 16, 2012

CodeChef/FACTORIAL


The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically.
The technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Traveling Salesman Problem" and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1.2.3.4....N. The number is very high even for a relatively small N.
The programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behavior of the factorial function.
For example, they defined the function Z. For any positive integer NZ(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbersN1<N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently.

Input

There is a single positive integer T on the first line of input (equal to about 100000). It stands for the number of numbers to follow. Then there are T lines, each containing exactly one positive integer numberN, 1 <= N <= 1000000000.

Output

For every number N, output a single line containing the single non-negative integer Z(N).

Example

Sample Input:
6
3
60
100
1024
23456
8735373
Sample Output:
0
14
24
253
5861
2183837




package com.factorial;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  try {
   String temp=br.readLine();
   int noofInp=Integer.parseInt(temp);
   int inputArray[]=new int[noofInp];
   for (int i = 0; i < noofInp; i++) {
    temp=br.readLine();
    inputArray[i]=Integer.parseInt(temp);
   }
   for (int i = 0; i < noofInp; i++) {
//    /System.out.println(inputArray[i]);
    int result=calctrailingZeros(inputArray[i]);
    System.out.println(result);
   }
   
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  

 }

 private static int calctrailingZeros(int val) {
  // TODO Auto-generated method stub
  int i=1;
  int result=1;
  int ret=0;
  while(result>=1)
  {
   result=(int) (val/Math.pow(5,i));
   i++;
   ret+=result;
  }
  
  return ret;
  
 }

}

CodeSprint/Coin Toss


/* Enter your code here. Read input from STDIN. Print output to STDOUT */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;

public class Solution {


public static void main (String args[]) throws IOException
{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
double solutionArray[];
int anArray[] = new int [2] ;
String Delims=" ";
String temp= br.readLine();
int counter= Integer.parseInt(temp);
String[] tempArray= new String[counter];
solutionArray= new double[counter];
for (int i = 0; i < counter; i++) {
tempArray[i]=br.readLine();
}

DecimalFormat df = new DecimalFormat("##.00");
for (int lubaluba=0;lubaluba<counter;lubaluba++)
{
String andrtemp[]=tempArray[lubaluba].split(Delims);
anArray[0]=Integer.parseInt(andrtemp[0]);
anArray[1]=Integer.parseInt(andrtemp[1]);
// System.out.print("Parsed values are"+anArray[0]+"and"+anArray[1]);
if (anArray[0]==(anArray[1])&&(counter==1))
{
String chumma="0.00";
System.out.println(chumma);
System.exit(1);
}
if(anArray[0]>anArray[1])
{
double val1= Math.pow(2, anArray[0]+1);
double val2= Math.pow(2, anArray[1]+1);
double sol=val1-val2;
solutionArray[lubaluba]=sol;
}
else if (anArray[0]==(anArray[1]))
{
double chumma=0;
solutionArray[lubaluba]=chumma;
}

}

for (int i = 0; i < solutionArray.length; i++)
{
if (solutionArray[i]==0)
{
System.out.println("0.00");
}
else
{
System.out.println(df.format(solutionArray[i]));
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
br.close();
}
}

Interview Street/String Similarity


/* Enter your code here. Read input from STDIN. Print output to STDOUT */
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Solution {

/**
* @author manish
*/

public static void main(String[] args)
{
int no=0;
String[] baseArray;
int[] total;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
no = Integer.parseInt(br.readLine());
baseArray= new String[no];
total =new int[no];
for (int cnt=0;cnt<baseArray.length;cnt++)
{
baseArray[cnt]= br.readLine();
total[cnt] = baseArray[cnt].length();
}
for(int count = 0;count <baseArray.length;count++)
{
for (int i = 1; i < baseArray[count].length(); i++)
{
String test=baseArray[count].substring(i);  
int retVal=maxMatch(test,baseArray[count]);
total[count]= total[count]+retVal;
}
System.out.print(total[count]+"\n");
}
}
catch(Exception e)
{
//System.out.println("Problem");
}
}

private static int maxMatch(String s,String str)
{
// TODO Auto-generated method stub
int counter=0;
char[] main_String = str.toCharArray();      
char[] substring = s.toCharArray();
for (int i = 0; i < substring.length; i++) {
if(substring[i]==main_String[i])
{
counter++;
}
else
return counter;
}
return counter;
}
}