Sunday, September 29, 2013

15567. Playing With Balls

IITKWPCN

   There are W white balls and B black balls in a bag. A magician is performing tricks by drawing balls from the bag.

    In each step, the magician randomly removes any two balls from the bag. If the drawn balls are of the same color, he will put one white ball in the bag, otherwise he will put a black ball in it. The two drawn balls from the bag from the ball are discarded.
    He keeps on doing the above tricks until there is only one ball remaining in the bag.
    Given W and B, you have to determine the probability that the color of last ball remaining in the bag is black. You should print the answer with accuracy of upto 6 decimal digits.

CODE

 

t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    w=int(str[0])
    b=int(str[1])
    c=b%10
    if(b%2==0):
        print("0.000000")
    else:
        print("1.000000")
 


 



7430. Tower Of Hanoi - Revisited

Given 3 three pegs: leftmost peg A, middle peg B and rightmost peg C.Find the shortest sequence of moves that transfers a tower of n disks from the left peg A to the right peg C, if direct moves between A and C are disallowed. (Each move must be to or from the middle peg B.)

Constraints:
1. Initially the left peg A in stacked by n disks in the order of decreasing size.
2. Only one move cand be done at a time and never moving a larger one onto a smaller.
3. Number of moves will always be less than 2^64.
4. 1 <= n <= 35


CODE

t=input()
for i in range(t):
    a=input()
    print (3**a-1)

Sunday, September 15, 2013

<data:blog.pageName/> |<data:blog.title/>ubuntu proxy setting linux proxy setting "proxy-setter" ubuntu ubuntu 13.04 ubuntu 12.10 ubuntu 12.04 ubuntu 11.10 linux python proxy apt-get http https ftp gtk tool <data:blog.pageTitle/>ubuntu proxy setting linux proxy setting "proxy-setter" ubuntu ubuntu 13.04 ubuntu 12.10 ubuntu 12.04 ubuntu 11.10 linux python proxy apt-get http https ftp gtk tool "ubuntu proxy setting"
"linux proxy setting"
"proxy-setter"
"ubuntu" "ubuntu 13.04" "ubuntu 12.10" "ubuntu 12.04" "ubuntu 11.10"
"linux"
"python" "proxy apt-get"
"http" "https" "ftp" "gtk tool"


#!/usr/bin/python
#
#   "Super Proxy Setter"
#   with GTK Interface
#
#   Ubuntu proxy setting tool.
#   This sets the apt,bash and profile config-files.
#   Network proxy-settings with user-name and password can only be configured with this tool .
#  
#   Supports Ubuntu 8.04 - Ubuntu 13.04 (Latest as of Sep 2013)

#   A tool to configure proxy-settings in universities and office environmment.
#   It Eliminates the need of doint editing again and again of system files that is prone to frequent manual errors. 
#   Atleast 3 different configuration files needs to be modified to configure proxy settings,
#   especially the network proxy-settings with username and password.
#   This can be used in an environment where ("http","https" and the "ftp") proxies have the same or different settings.
#  
#
#
#
#   Author:  Abdul Qadir Faridi , Pankaj Chaudhary
#
#   E-mail:  aqfaridi[@]gmail[.]com , pankaj9310[@]gmail[.]com
#
#   Date:    16/9/2013
#   Meta:  
#            Abdul Qadir Faridi , Pankaj Chaudhary
#            Linux Community
#            ABV - Indian Institute of Information Technology and Management - Gwalior
#
#   Powered By:
#               Ubuntu 11.10 & Vi IMproved 7.3
#  
#
#   Ver.- 1.0.0
#
#   ReadMe -  1) chmod 777 spsetter
#          2) sudo ./spsetter   
#
https://github.com/pankaj9310/proxy-setter
https://github.com/aqfaridi/super-proxy-setter/blob/master/spsetter.py
https://www.dropbox.com/sh/uv6ig21btedm1kb/ppXbABcSHJ
https://www.dropbox.com/sh/uv6ig21btedm1kb/DkskxPzBIt/spsetter.zip
https://www.dropbox.com/home/proxy-setter?select=spsetter.tar.gz

Sunday, August 25, 2013

The last digit

LASTDIG
Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. You have to find the last digit of a^b.


CODE



import math
t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    a=int(str[0])
    b=int(str[1])
    if(b==0):
        print 1
    else:
        a=a%10
        b=b%4
        if(b==0):
            b=4
        print pow(a,b)%10
 

Kamil

KAMIL
Some kids cannot pronounce all letters, some of them they sometimes pronounce correctly and sometimes incorrectly. Kamil sometimes says T instead of K, but he never says K instead of T. Similarly he sometimes says D instead of G. Instead of R he sometimes says L and sometimes F. Of course it happens that he pronounces the letter correctly. Kamil's father always thinks how many words can mean the word spoken by his son (it doesn't matter if they are real English words).


code


for i in range(10):
    t=raw_input();
    print 2**sum(t.count(i)for i in'DFLT')


 

Friday, August 9, 2013

3932. Point Connection Game in a Circle


MCIRGAME/
CODE

def fac(n):
    if(n==0):
        return 1
    else:
        return n*fac(n-1)
while(True):
    k=input()
    if(k==-1):
        break
    else:
        temp=fac(2*k)/(fac(k+1)*fac(k))
        print temp


9952. 111…1 Squared

Problem code: GUANGGUN

CODE

import sys
for s in sys.stdin:
    n=int(s)
    if(n<10):
        print n*n
    else:
        t=(n-10)/9+1
        k=10+(t-1)*9
        ans=((81*t)+1)+((n-k)*(n-k+2))
        print ans

   

 

 UCV2013I

CODE

import math
while(True):
    s=raw_input()
    str=s.split(' ')
    r=int(str[0])
    n=int(str[1])
    if(n==0 & r==0):
        break;
    else:
        x=math.pi/2
        R=r/math.sin(x/n)
        print ("%.2f")%R

Sunday, July 28, 2013

15388 Easy One For Cartman

Easy One For Cartman

CODE
import math
t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    a=int(str[0])
    b=int(str[1])
    n=int(str[2])
    d=b-a
    ans=n*(2*a+(n-1)*d)/2
    #ans=(pow(n%1000000007,r%1000000007))%1000000007
    print ans

TRAINGLE

TRYANGLE
CODE

import math
t=int(input())
for i in range(1,t+1):
    n=int(input())
    ans=(n*(n-1)*(n-2))/6
    print "Case %d: %d" % (i,ans)
Counting Ids
CODE

import math
while(True):
    s=raw_input()
    str=s.split(' ')
    n=int(str[0])
    r=int(str[1])
    if(n==0 & r==0):
        break;
    else:
        ans=(n*(pow(n,r)-1)/(n-1))%1000000007
        print (ans)

Monday, June 17, 2013

Saturday, June 1, 2013

14863. Summation of Multiples

http://www.spoj.com/problems/SUM1/


CODE

t=int(input())
for i in range(t):
    n=int(input())
    a=(n-1)/3
    b=(n-1)/5
    c=(n-1)/15
    ans=(3*a*(a+1)/2)+(5*b*(b+1)/2)-(15*c*(c+1)/2)
    print(ans)

Saturday, May 25, 2013

1. Life, the Universe, and Everything

http://www.spoj.com/problems/TEST/

CODE

while(True):
    n=int(input())
    if(n==42):
        break
    else:
        print(n)

Thursday, May 23, 2013

6297. Decipher

http://www.spoj.com/problems/ROOTCIPH/

Code

 t=int(input())
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    a=int(str[0])
    b=int(str[1])
    c=int(str[2])
    print(a*a-2*b)


9935. Break the Chocolate

http://www.spoj.com/problems/BC/


from math import log, ceil
ct = input()
i = 1
while ct:
    ct -= 1
    a, b, c = map(int, raw_input().split())
    t = a * b * c
    x = ceil(log(a, 2)) + ceil(log(b, 2)) + ceil(log(c, 2))
    print "Case #%d: %d %d" % (i, t - 1, int(x))
    i += 1

11931. AMZ Word

http://www.spoj.com/problems/AMZSEQ/
lst = [0] * 25
lst[0] = 1
lst[1] = 3
for i in range(2, 25):
    lst[i] = 2 * lst[i - 1] + lst[i - 2]
n = input()
print lst[n]

Friday, March 8, 2013

AMR10F SPOJ

http://www.spoj.com/problems/AMR10F/
t=input()
for i in range(t):
    s=raw_input()
    str=s.split(' ')
    n=int(str[0])
    a=int(str[1])
    d=int(str[2])
    ans=n*a+(n-1)*d*n/2
    print ans

Monday, February 25, 2013


http://www.spoj.com/problems/GEOPROB/

t=input()
for i in range(0,t):
        s=raw_input()
        str=s.split(' ')
        b=int(str[0])
        c=int(str[1])
        d=int(str[2])
       
        print (c-b)+(c-d)
http://www.spoj.com/problems/TMUL/

t=input()
for i in range(0,t):
        s=raw_input()
        str=s.split(' ')
        b=int(str[0])
        c=int(str[1])
        a=int(b*c)
        print (a)