On Sunday, April 28, 2013 8:40:11 PM UTC+3, M.H. wrote:
> Isn't that a case that your algorithm performs, say, k iterations where k is 
> the result that you are going to output? If it is, isn't that a case that all 
> numbers that your program outputs before it hangs are relatively small (< 
> 100)? My large output for this problem has about 2000 small values in the 
> beginning and the rest are rather big values (>100000000).
> 
> 
> 
> 
> 
> 2013/4/28 Parveen Soni <[email protected]>
> 
> 
> It is not about the logic i following but problem occurs when i try to work 
> with 6000 input.
> It work fine with 2000 input and even,it does not stop at 1695th input but
> stops at 1695th input when run with 6000 input
> 
> 
> 
> 
> 
> 
> 
> On Sat, Apr 27, 2013 at 5:53 PM, Meili <[email protected]> wrote:
> 
> 
> 
> On Saturday, April 27, 2013 7:11:19 AM UTC-3, SONI wrote:
> 
> > My code for Small input was right but for large input cases,it stops 
> > working.Coding Language is java.
> 
> > Another Problem is,for first 2000 inputs of a large input file (in separate 
> > file),it works fine but if all 6000 inputs are given in a file,it calculate 
> > only up to 1694th input and stops at 1695 and does not respond anything.
> 
> 
> 
> >
> 
> > plz help me......................Thanx In Advance....:-)
> 
> 
> 
> u need to write a better algorithm. Brute force is not very good for large 
> inputs.
> 
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> 
> To post to this group, send email to [email protected].
> 
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/google-code/-/2qegCrFTTeMJ.
> 
> 
> 
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> You received this message because you are subscribed to the Google Groups 
> "Google Code Jam" group.
> 
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> 
> To post to this group, send email to [email protected].
> 
> For more options, visit https://groups.google.com/groups/opt_out.

the ink amount is the sum of an Arithmetic progression series.
Sn=(2*a1 +(n-1)*d)/2
Sn=amount of ink given
a1=starting radius
d=4
all you need to do is to solve a Quadratic equation.
the problem is that float is not big enough for big numbers, so I used a fixed 
point calculations.
my code is very simple and in python you can see it here: 
http://codeviewer.org/view/code:328d

or in plain text here:

import decimal
decimal.getcontext().prec = 100

def find_roots(a,b,c):
    a = decimal.Decimal(a)
    b = decimal.Decimal(b)
    c = decimal.Decimal(c)
    return 
((-b/(2*a))+(decimal.Decimal((b*b-4*a*c)/(4*a*a)).sqrt()),(((-b/(2*a))-decimal.Decimal((b*b-4*a*c)/(4*a*a)).sqrt())))

def get_n(a1,sn):
    return find_roots(2,(a1-2),-sn)

def get_rings_num(r,t):
    return int(max(get_n(2*r+1, t)))

def main(args):
    inf = open(args[1])
    outf = open(args[2], 'wt')
    for i in xrange(1,int(inf.readline())+1):
        r,t = (int(j) for j in inf.readline().split())
        outf.write("Case #%d: %d\n" % (i, get_rings_num(r,t)))
    
    
if __name__ == "__main__":
    import sys
    main(sys.argv)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-code/-/6k1Downxz94J.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to