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
def isWin(board): | |
""" | |
GIven a board checks if it is in a winning state. | |
Arguments: | |
board: a list containing X,O or -. | |
Return Value: | |
True if board in winning state. Else 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
def reduce(s): | |
global value, minimum | |
l = len(s) | |
minimum = l | |
if l == 1: | |
value = 1 | |
return True | |
elif l == 2 and s[0] == s[1]: | |
value = 2 | |
return True |
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
from math import sqrt | |
N = int(raw_input()) | |
x, y = [], [] | |
y = [] | |
for i in xrange(N): | |
temp = raw_input().split() | |
x.append(int(temp[0])) | |
y.append(int(temp[1])) | |
avg_x = sum(x) / N | |
avg_y = sum(y) / N |
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
N, R = int(raw_input()), [] | |
V = [1] * N | |
for x in xrange(N): | |
R.append(int(raw_input())) | |
while True: | |
finished = True | |
for i in xrange(N): | |
for k in [-1, 1]: | |
next = i + k | |
if next >= 0 and next < N and R[next] > R[i] and V[next] <= V[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 StrSimilar{ | |
public static void main(String[] args) { | |
java.util.Scanner sc=new java.util.Scanner(System.in); | |
int N=sc.nextInt(),sol; | |
while(N--!=0){ | |
sol=0; | |
char[] s=sc.next().toCharArray(); | |
for(int i=0;i<s.length;i++){ | |
for(int j=i;j<s.length;j++){ | |
if(s[j]==s[j-i]) sol++; |
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
line1=raw_input().split() | |
N,K,total,completed,Costs=int(line1[0]),int(line1[1]),0,0,[] | |
for n in raw_input().split():Costs.append(int(n)) | |
Costs.sort(reverse=True) | |
friend=[0]*K | |
for i in range(N): | |
friend[completed%K]+=1 | |
total=total+friend[completed%K]*Costs[i] | |
completed+=1 | |
print total |
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 java.util.*; | |
public class EvenTree { | |
public static void main(String args[]){ | |
Scanner s=new Scanner(System.in); | |
int n,m; | |
int e1,e2; | |
n=s.nextInt(); | |
m=s.nextInt(); | |
Tree t=new Tree(n); |
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
/* | |
ID: sudhaga1 | |
PROG: beads | |
LANG: C++ | |
*/ | |
#include "iostream" | |
#include "fstream" | |
using namespace std; | |
int main() |
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
/* | |
ID: sudhaga1 | |
PROG: milk | |
LANG: C++ | |
*/ | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
#define MAXCOSTS 1001 |
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
#include <iostream> | |
#include <stdio.h> | |
#include <string.h> | |
using namespace std ; | |
#define _(x,a) memset(x,a,sizeof(x)) | |
#define LET(x,a) __typeof(a) x(a) | |
#define FOR(i,a,b) for(LET(i,a);i!=(b);++i) | |
#define REP(i,n) FOR(i,0,n) | |
#define GI ({int t;scanf("%d",&t);t;}) |
OlderNewer