def solve(N, ss): f = 0 c = 0 for i, s in enumerate(ss): if c < i: f += i - c c += i - c
c += s
return f, c
for i in range(T): N, S = fin.readline().split() ss = [] for j in range(int(N)+1): ss.append(int(S[j])) solution = solve(int(N), ss) answer = "Case #%d: %s\n" % (i+1, solution[0]) print answer fout.write(answer)
def mult(qs): r = q('1') for vq in qs: r = r * vq return r
def mult_table(table, vs, a, b, indices): key = str(a) + ',' + str(b) if table.has_key(key): return table[key] else: cs = [x for x in indices if a < x < b] if not cs: value = mult(vs[a:b]) else: c = cs[len(cs)/2] value = mult_table(table, vs, a, c, indices) * mult_table(table, vs, c, b, indices) #print key, value, a, c, b table[key] = value return value
#print q('i') * q('j'), q('j') * q('k'), q('i') * q('j') * q('k') def solve(L, X, ijk): fqs = [] for i in ijk: if i == 'i' or i == 'j' or i == 'k': fqs.append(q(i)) qs = [] X = X % 16 extend = min(X, 4) for i in range(extend): qs.extend(fqs)
print qs lq = q('1') left_plus = [] left_minus = [] for i_l, l in enumerate(qs): # print lq, l lq = nx = lq * l if nx == q('i'): left_plus = [i_l+1, nx, l] if nx == -q('i'): left_minus = [i_l+1, nx, l] if left_plus and left_minus: break right_plus = [] right_minus = [] rq = q('1') for i_r, r in enumerate(reversed(qs)): rq = nx = r * rq if nx == q('k'): right_plus = [i_r+1, nx, r] elif nx == -q('k'): right_minus = [i_r+1, nx, r] if right_plus and right_minus: break if (not left_plus) and not left_minus: return "NO" if not right_plus and not right_minus: return "NO" dqs = [] for idqs in range(X):#range(min(X, 8)): dqs.extend(fqs)
lefts = [] rights = []
mc = {} mfqs = mult(fqs) indices = [] if left_plus: indices.append(left_plus[0]) lefts.append(left_plus) if left_minus: indices.append(left_minus[0]) lefts.append(left_minus) if right_plus: indices.append(len(dqs) - right_plus[0]) rights.append(right_plus) if right_minus: indices.append(len(dqs) - right_minus[0]) rights.append(right_minus) for ie in range(8): index = ie * len(fqs) indices.append(index) mc[str(index) + ',' + str(index + len(fqs))] = mfqs sorted_indices = sorted(set(indices))
# prev = -1 # mc = mult_table(qs, sorted_indices) # for ii in sorted_indices: # for ij in sorted_indices[]: # if # if prev > 0 # mc[[prev, index]] = mult(qs[prev:index+1]) # prev = index print mfqs, mc, sorted_indices for j_l in lefts: for j_r in rights: if j_l[0] + j_r[0] < len(dqs) + 2: #isj = mult_table(mc, dqs, j_l[0], len(dqs)-j_r[0], sorted_indices) isj = mult(dqs[j_l[0] : len(dqs) - j_r[0] ]) #print j_l[1], isj, j_r[1], j_l[1] * isj * j_r[1] if j_l[1] * isj * j_r[1] == -q('1'): return "YES" # else: # j_left = mult(dqs[j_l[0] : -1]) # j_right = mult(dqs[0 : len(dqs) - j_r[0]]) # j_middle = q('1') # for k_d in range(min(X - 8, 4)): # j_middle = j_middle * mfqs # if j_l[1] * j_left * j_middle * j_right * j_r[1] == -q('1'): # return "YES" return "NO" for i in range(T): L, X = map(int, fin.readline().split()) ijk = fin.readline() solution = solve(L, X, ijk) # if solution > candidate: # print 'ERROR', i + 1, solution, candidate # if solution != solution1: # print 'ERROR', i + 1, solution, solution1, candidate answer = "Case #%d: %s\n" % (i + 1, solution) print answer fout.write(answer)
Gabriel = "GABRIEL" Richard = "RICHARD" def solve(X, R, C): if (R * C) % X != 0: print "%" return Richard if R < X and C < X: print "<" return Richard if X > 6: print "6" return Richard min_l = 1 + (X - 1) / 2 if X > 2 and (R < min_l or C < min_l): print "sqrt" return Richard snake = 2 + (X - 2) / 3 if X > 3 and (R <= snake or C <= snake): print "snake" if X == 4: return Richard elif X == 5 and (R < 5 and C < 5): return Richard elif X == 6 and (R < 7 and C < 7): return Richard
return Gabriel
for i in range(T): X, R, C = map(int, fin.readline().split()) print i+1, X, R, C
solution = solve(X, R, C) # if solution > candidate: # print 'ERROR', i + 1, solution, candidate # if solution != solution1: # print 'ERROR', i + 1, solution, solution1, candidate answer = "Case #%d: %s\n" % (i + 1, solution) print answer fout.write(answer)
Core Animation in Practice, Part 1Graphics & MediaiOS Core Animation in Practice, Part 1 Core Animation is the layer-based animation system that powers the dynamic user experience seen in iPhone OS. See Core Animation in action and learn about its architecture, capabilities, and best practices. Learn how to combine the familiar capabilities of UIKit, Quartz 2D, and OpenGL ES with the power of Core Animation layers and animation. Download: HD | SD | PDF System Requirements To watch the streaming version of this video, use the latest version of Safari on a Mac running OS X Lion or later. Alternatively, you can download this video in HD and SD. Core Animation in Practice, Part 2Graphics & MediaiOS
WWDC 2010 Session 123 – Building Animation Driven Interfaces WWDC 2010 Session 424 – Core Animation in Practice, Part 1 WWDC 2010 Session 425 – Core Animation in Practice, Part 2
extra offscreen passes when updating content -->> 정적인 content에 쓰기
cache size는 2.5x of screen size에 한정돼있으니까 overuse하지 말기.
rasterized images는 100ms 이상 동안 안쓰인다면 evicted from cache
Tools
performance issue가 있다면, 생각해 보자
frame rate = 60 frame/sec
CPU or GPU bounds
GPU desirable > CPU
fewer offscreen passes
less blending
Dont use strange image formats
visual effects costs
view hierarchy
Instruments
Core animation instrument, OpenGL ES drivier instrument
color blended layers에 check하면, 얼마나 겹쳐 있는지 알 수 있다.
color hit green and ... red: cache 안돼있을 때 빨갛게 표시
color copied images: 지원 안하는 color format 때문에 시간 걸릴 때
color misaligned image
color offscreen yellow
2012, 2013 년에는 mac os x Cocoa Animation
Best Practices for Cocoa Animation
Frameworks
OS X
https://developer.apple.com/videos/wwdc/2012/
Layer-Backed Views: AppKit + Core Animation Essentials OS X Layer-Backed Views: AppKit + Core AnimationPlay Learn how to effectively use layer-backed views in AppKit to...
def solve(outlets, plugs, N, L): #print outlets, plugs plugs.sort()
shuffle = [] switch = [] unknown = [] for i in range(L): ips = [(p >> i) % 2 for p in plugs] ios = [(o >> i) % 2 for o in outlets] print i, ips, ios if ips.count(1) == ios.count(1): if ips.count(1) == ips.count(0): unknown.append(i) elif ips.count(0) == ios.count(1): if ips.count(1) == ips.count(0): unknown.append(i) else: shuffle.append(i) else: return "NOT POSSIBLE" shuffled_outlets = outlets[:] for s in shuffle: shuffled_outlets = [o ^ pow(2, s) for o in shuffled_outlets]
result = len(shuffle) print plugs print shuffled_outlets
if plugs == shuffled_outlets: return str(result)
for i in range(len(unknown)): for j in itertools.combinations(unknown, i+1): shuffled_outlets2 = shuffled_outlets[:] for k in j: shuffled_outlets2 = [o ^ pow(2, k) for o in shuffled_outlets2] shuffled_outlets2.sort() #print shuffled_outlets if plugs == shuffled_outlets2: return str(result + i + 1)
return "NOT POSSIBLE" for i in range(T): N, L = map(int, fin.readline().split()) outlets = [int(n, 2) for n in (fin.readline().split())] plugs = [int(n, 2) for n in (fin.readline().split())] print 'o', outlets print 'p', plugs solution = solve(outlets, plugs, N, L) if N == 1 and solution == "NOT POSSIBLE": print "ERROR1" if solution != "NOT POSSIBLE" and N < int(solution): print "ERROR2" answer = "Case #%d: %s\n" % (i+1, solution) print answer fout.write(answer)
#sorted_star2_indices = [v[0] for v in sorted(enumerate(star2s), key=lambda x:x[1])] sorted_star2_indices = [v[0] for v in sorted(enumerate(star2s), cmp=greater)] sorted_star2_values = [v[1] for v in sorted(enumerate(star2s), cmp=greater)]
for i in range(T): N = int(fin.readline()) stars = [] completed = [] for j in range(N): stars.append(map(int, fin.readline().split())) completed.append(False)
RECENT COMMENT