This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
M=[True] * 1000000 | |
M[0] = M[1] = False | |
for i in xrange(2, len(M)): | |
# print i | |
if M[i]: | |
j = i + i | |
while j < len(M): | |
M[j] = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
M=[True] * 1000000 | |
M[0] = M[1] = False | |
for i in xrange(2, len(M)): | |
# print i | |
if M[i]: | |
j = i + i | |
while j < len(M): | |
M[j] = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
if __name__=='__main__': | |
lines = [int(x.strip()) for x in sys.stdin.readlines() if x != '' and x != '\n'] | |
n = lines[0] | |
for i in xrange(n): | |
# a, b = int(lines[i+1]), int(lines[i+2]) | |
a, b = lines[2*i+1], lines[2*i+2] | |
if len(str(a+b)) > 80: | |
print 'overflow' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! -*- coding: utf-8-unix -*- | |
import math | |
if __name__=='__main__': | |
n = int(raw_input()) | |
for i in xrange(n): | |
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, raw_input().strip().split(' ')) | |
if math.fabs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)) < 1e-10: | |
print 'YES' | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! -*- coding: utf-8-unix -*- | |
import math | |
if __name__=='__main__': | |
n = int(raw_input()) | |
for i in xrange(n): | |
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, raw_input().strip().split(' ')) | |
if math.fabs((y2 - y1) * (x4 - x3) - (y4 - y3) * (x2 - x1)) < 1e-10: | |
print 'YES' | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! -*- coding: utf-8-unix -*- | |
import sys | |
if __name__=='__main__': | |
lines = [x.strip() for x in sys.stdin.readlines() if x != '' and x != '\n'] | |
for line in lines: | |
cs = line.split() | |
stack = [] | |
res = 0.0 | |
for c in cs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! -*- coding: utf-8-unix -*- | |
import sys | |
def overlap(p1, p2): | |
# print p1, p2,(p1[0]-p2[0]) ** 2 + (p1[1] - p2[1])**2 | |
return (p1[0]-p2[0]) ** 2 + (p1[1] - p2[1])**2 <= 4 | |
if __name__=='__main__': | |
lines = [x.strip() for x in sys.stdin.readlines() if x != '' and x != '\n'] | |
# print lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BallAndHats | |
{ | |
public: | |
int getHat(string hats, int numSwaps) | |
{ | |
int idx = hats.find("o"); | |
if (numSwaps == 0) return idx; | |
return (idx + (numSwaps % 2)) % 2; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EasyConversionMachine { | |
public: | |
string isItPossible(string originalWord, string finalWord, int k) { | |
string POSSIBLE = "POSSIBLE"; | |
string INPOSSIBLE = "IMPOSSIBLE"; | |
int n = originalWord.size(); | |
int i; | |
int diff=0; | |
for(i = 0; i < n; i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RotatingBot { | |
public: | |
int minArea(vector <int> moves) { | |
int MAX_W = 55; | |
int MAX_H = 55; | |
int newmap[MAX_H*2][MAX_W*2]; | |
vector< vector<int> > map(MAX_H*2); | |
int i,j; | |
for(i = 0; i < MAX_H*2; i++){ | |
map[i] = vector<int>(MAX_H*2); |
OlderNewer