Hi,
is my code for kickstart round A correct for evendigits
T = int(input())
for i in range(T):
s = input()
if "1" not in s and "3" not in s and "5" not in s and "7" not in s
and 9 not in "s":
print("Case #"+str(i+1)+": "+str(0))
elif len(s) == 1:
print("Case #" + str(i + 1) + ": " + str(1))
else:
neg = ""
pos = ""
a = 0
while(True):
if s[a] == '1' or s[a] == '3' or s[a] == '5' or s[a] ==
'7' or s[a] == '9':
neg = neg + str(int(s[a])-1)
pos = pos + str(int(s[a])+1)
a+=1
while(a < len(s)):
pos = pos + str(0)
neg = neg + str(8)
a+=1
break
else:
neg = neg+s[a]
pos = pos+s[a]
a+=1
neg = int(s) - int(neg)
pos = int(pos) - int(s)
m = min(neg,pos)
print("Case #" + str(i + 1) + ": " + str(m))
On Thu, Apr 12, 2018 at 5:29 PM, Yupeng Gu <[email protected]> wrote:
> Seems to me like you are checking from left to right whether there is a
> chance to swap in the main function?
>
> If yes, then the problem is that to get the maximum reduction of damage,
> we should reduce the energy of the shooting that has been charged most,
> therefore it should be from right to left instead.
>
> Another thing is that maybe before you swap all shooting and charging that
> could be swapped in a loop, the damage has already been reduced to a
> value<=threshold. Therefore I suggest you to check after each swap.
>
> On Thursday, April 12, 2018 at 10:19:21 AM UTC-7, Sahil Shetty wrote:
> > def change(rcodeC, i):
> >
> > holder = rcodeC[i + 1]
> > rcodeC[i + 1] = rcodeC[i]
> > rcodeC[i] = holder
> > return rcodeC
> >
> > def damage(rcodeD, dmg = 0, count = 0):
> >
> > for i in rcodeD:
> >
> > if i == 'S': dmg += 2 ** count
> > else: count += 1
> >
> > return dmg
> >
> >
> > def main(shield, rcode, hacks = 0, count = 0):
> >
> > while damage(rcode) > shield:
> >
> > for i in range(len(rcode) - 1):
> >
> > try:
> >
> > if rcode[i] == 'C' and rcode[i + 1] != 'C':
> >
> > hacks += 1
> > rcode = change(rcode, i)
> >
> > try:
> >
> > if all(e == 'C' for e in rcode[rcode.index('C'):
> -1]) == True and damage(rcode) > shield: return 'IMPOSSIBLE'
> >
> > except ValueError:
> >
> > if all(e == 'S' for e in rcode[rcode.index('S'):
> -1]) == True and damage(rcode) > shield: return 'IMPOSSIBLE'
> >
> > except IndexError: None
> >
> > return hacks
> >
> >
> > test = int(raw_input("Test data: "))
> > print '\n'
> > while test < 1 or test > 100: test = int(raw_input("Between 1 and 100:
> "))
> >
> > for i in range(test):
> >
> > shield = int(raw_input("Shield strength: "))
> > while shield < 1 or shield > (10 ** 9): shield =
> int(raw_input("Between 1 and 10^9: "))
> >
> > rcode = raw_input("Robot code: ")
> > while all(i == 'C' or i == 'S' for i in rcode) != True or len(rcode)
> > 30 or len(rcode) < 2: rcode = raw_input("Must be greater than 2 and less
> than 1; only 'C' and 'S': ")
> >
> >
> > print 'Case #' + str(i + 1) + ':', main(shield, list(rcode)),
> '\n\n\n'
>
> --
> 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/
> msgid/google-code/b53e0bdf-6910-406f-90e4-e1667a902a5a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
--
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/msgid/google-code/CADYapveoUQV%3DhSs0iW2igssXcbASw47k6xXhdBz7VB8_4kzjYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.