Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Jul 17, 2018
2 parents 012c35f + 9d8ab08 commit b37bf08
Show file tree
Hide file tree
Showing 153 changed files with 6,769 additions and 0 deletions.
58 changes: 58 additions & 0 deletions CP/ C Cubed/prob1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import math
import statistics
import itertools

def findsubsets(S,m):
return set(itertools.combinations(S, m))
def readInts():
return list(map(int, input().split()))
def readInt():
return int(input())

n = readInt()
a = []

for __ in range(n):
inp = readInt()
if(inp>=0):
a.append(inp)
n = len(a)
# print(a)

summ = 0

for i in range(1,len(a)+1):
s = []
if(i&1):
s = findsubsets(a,i)
s = list(s)
for j in range(len(s)):
med = statistics.median(s[j])
summ+=med
print(summ)


'''
4
0
1
3
2
9
6
-9
7
2
-2
3
2
0
1
4
1
2
2
-2
'''
59 changes: 59 additions & 0 deletions CP/ C Cubed/prob2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import math
from itertools import combinations

def readInts():
return list(map(int, input().split()))
def readInt():
return int(input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStr():
return raw_input()
def euclid(x1,y1,x2,y2):
return math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
def manhat(x1,y1,x2,y2):
return abs(x1-x2)+abs(y1-y2)

n = readInt()
a = []
for i in range(n):
a.append(readInts())
# print(a)
ans =0
count =0
a = combinations(a, 2)
for i in list(a):
# print(i)
count+=1
# print(euclid(i[0][0],i[0][1],i[1][0],i[1][1]),manhat(i[0][0],i[0][1],i[1][0],i[1][1]))
if(euclid(i[0][0],i[0][1],i[1][0],i[1][1])==manhat(i[0][0],i[0][1],i[1][0],i[1][1])):
# print(i[0][0],i[0][1],i[1][0],i[1][1])
ans += 1
print(ans)


'''
Input:
3
1 1
7 5
1 5
Output:
3
Input:
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output:
12
'''
Empty file added CP/ Code Conquest/prob1.py
Empty file.
68 changes: 68 additions & 0 deletions CP/ Codenigma/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Akash Kandpal
# My Domain => http://harrypotter.tech/
# from fractions import gcd
import math
# from itertools import permutations
# import statistics

def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()
def numlistTostr(list1):
return ''.join(list1)
def strlistTostr(list1):
return ''.join(str(e) for e in list1)
def strTolist(str):
return str.split()
def strlistTointlist(str):
return map(int, str)
def slicenum(number,x):
return int(str(number)[:x])
def precise(num):
return "{0:.10f}".format(num)
def rsorted(a):
return sorted(a,reverse=True)
def binar(x):
return '{0:031b}'.format(x)
def findpermute(word):
perms = [''.join(p) for p in permutations(word)]
return set(perms)
def findsubsets(S,m):
return set(itertools.combinations(S, m))
def sort1(yy,index):
return yy.sort(key = lambda x:x[index])
def reversepair(yy):
return yy[::-1]

MOD = 10 ** 9 + 7

for __ in range(readInt()):
n = readInt()
# maxi = -1e9
# for i in range(n+1):
# for j in range(n+1):
# # print i,j
# if(abs(i**2-j**2)==n):
# print i,j
# maxi = max(maxi,i+j)
# print maxi
print n

'''
Input:
3
1
7
35
Output:
1
'''
60 changes: 60 additions & 0 deletions CP/ Codenigma/p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Akash Kandpal
# My Domain => http://harrypotter.tech/
# from fractions import gcd
import math
# from itertools import permutations
# import statistics

def readInts():
return list(map(int, raw_input().strip().split()))
def readInt():
return int(raw_input())
def readIntsindex0():
return list(map(lambda x: int(x) - 1, input().split()))
def readStrs():
return raw_input().split()
def readStr():
return raw_input()
def numlistTostr(list1):
return ''.join(list1)
def strlistTostr(list1):
return ''.join(str(e) for e in list1)
def strTolist(str):
return str.split()
def strlistTointlist(str):
return map(int, str)
def slicenum(number,x):
return int(str(number)[:x])
def precise(num):
return "{0:.10f}".format(num)
def rsorted(a):
return sorted(a,reverse=True)
def binar(x):
return '{0:031b}'.format(x)
def findpermute(word):
perms = [''.join(p) for p in permutations(word)]
return set(perms)
def findsubsets(S,m):
return set(itertools.combinations(S, m))
def sort1(yy,index):
return yy.sort(key = lambda x:x[index])
def reversepair(yy):
return yy[::-1]

MOD = 10 ** 9 + 7

for __ in range(readInt()):
n,m = readInts()
ans = m*(2*m+1)*(2*m-1)/3
# print ans
ans -= n*(2*n+1)*(2*n-1)/3
print ans % MOD

'''
Input:
1
1 4
Output:
83
'''
114 changes: 114 additions & 0 deletions CP/ Codenigma/p3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// C++ program to to find all pairs such that
// a % b = k.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

// Utiltity function to find the divisors of
// n and store in vector v[]
vector<int> findDivisors(int n)
{
vector<int> v;

// Vector is used to store the divisors
for (int i = 1; i<= sqrt(n); i++)
{
if (n%i == 0)
{
// If n is a square number, push
// only one occurrence
if (n/i == i)
v.push_back(i);
else
{
v.push_back(i);
v.push_back(n/i);
}
}
}
return v;
}

// Function to find pairs such that (a%b = k)
ll printPairs(ll arr[], ll n, ll k)
{
// Store all the elements in the map
// to use map as hash for finding elements
// in O(1) time.
int ans =0;
unordered_map<int, bool> occ;
for (int i = 0; i < n; i++)
occ[arr[i]] = true;

// bool isPairFound = false;
for (int i = 0; i<n ; i++ )
{
// Print all the pairs with (a, b) as
// (k, numbers greater than k) as
// k % (num (> k)) = k i.e. 2%4 = 2
if (occ[k] && k < arr[i])
{
// cout << "(" << k << ", " << arr[i] << ") ";
ans +=1;
// isPairFound = true;
}

// Now check for the current element as 'a'
// how many b exists such that a%b = k
if (arr[i] >= k)
{
// find all the divisors of (arr[i]-k)
vector<int> v = findDivisors(arr[i]-k);

// Check for each divisor i.e. arr[i] % b = k
// or not, if yes then print that pair.
for (int j = 0; j < v.size(); j++)
{
if (arr[i]%v[j] == k &&
arr[i]!= v[j] &&
occ[v[j]])
{
ans+=1;
// cout << "(" << arr[i] << ", "
// << v[j] << ") ";
// isPairFound = true;
}
}

// Clear vector
v.clear();
}
}

return ans;
}

// Driver program
int main()
{
// your code goes here
#ifdef JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll arr[651010];
ll n,k,t;
cin>>t;
while(t--){
cin>>n>>k;
for(ll i =0 ;i<n;i++){
arr[i]=i+1;
}
ll ans = printPairs(arr, n, k);
if (ans == 0)
cout <<"0"<<endl;
else
cout<<ans<<endl;
}

return 0;
}
17 changes: 17 additions & 0 deletions CP/ February Challenge 2018/prob1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re

for _ in range(int(input())):
c = 0
s = raw_input()
pattern = ['c','h','e','f']
# s = ''.join([i for i in s if i.isalpha()])
# s = s.lower()
for i in range(len(s)-3) :
if(s[i] in pattern and s[i+1] in pattern and s[i+2] in pattern and s[i+3] in pattern and s[i]!=s[i+1] and s[i]!=s[i+2] and s[i]!=s[i+3] and s[i+1]!=s[i+2]):
if(s[i+1]!=s[i+3] and s[i+2]!=s[i+3]):
c+=1
# print(s[i]+s[i+1]+s[i+2]+s[i+3])
if(c>0):
print "lovely",c
else :
print "normal"
Loading

0 comments on commit b37bf08

Please sign in to comment.