1
0
Fork 0

A new project is coming

This commit is contained in:
Nguyễn Gia Phong 2019-02-13 20:48:02 +07:00
parent ce56bd193a
commit 477c426b55
4 changed files with 30 additions and 8 deletions

6
codechef/chefing.py Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python3
from functools import reduce
from operator import and_
for _ in range(int(input())):
print(len(reduce(and_, (set(input()) for _ in range(int(input()))))))

9
codechef/depchef.py Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env python3
for _ in range(int(input())):
input()
a, d = ([int(i) for i in input().split()] for _ in range(2))
a.extend((a[0], a[-1]))
try:
print(max(d for i, d in enumerate(d) if d > a[i-1] + a[i+1]))
except ValueError:
print(-1)

5
codechef/hmappy2.p6 Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env perl6
for ^get() {
my ($N, $A, $B, $K) = get.words.map: *.Int;
put $N div $A + $N div $B - $N div ($A lcm $B) * 2 < $K ?? 'Lose' !! 'Win';
}

View File

@ -102,7 +102,7 @@ sub bubble-sort(@seq is copy) {
$done = True;
for ^@seq.end -> $i {
if @seq[$i] > @seq[$i+1] {
@seq[$i, $i + 1] = @seq[$i + 1, $i];
@seq[$i, $i + 1] .= reverse
$done = False
}
}
@ -114,7 +114,7 @@ sub bubble-sort(@seq is copy) {
sub select-sort(@seq is copy) {
for ^@seq.end -> $i {
for $i..@seq.end -> $j {
@seq[$i, $j] = @seq[$j, $i] if @seq[$i] > @seq[$j]
@seq[$i, $j] .= reverse if @seq[$i] > @seq[$j]
}
}
@seq
@ -124,7 +124,7 @@ sub select-sort(@seq is copy) {
sub insert-sort(@seq is copy) {
for 1..@seq.end -> $i {
loop (my $j = $i; $j and @seq[$j] < @seq[$j - 1]; $j--) {
@seq[$j, $j - 1] = @seq[$j - 1, $j]
@seq[$j, $j - 1] .= reverse
}
}
@seq
@ -232,7 +232,7 @@ sub has-duplicates(@array) { @array.unique != @array }
# Exercise 9.8
sub birthday-paradox(Int $n, Int $T) {
sum(map { has-duplicates map { Int(rand * 365.25) }, ^$n }, ^$T) / $T
sum(map { has-duplicates map { 365.25.rand.Int }, ^$n }, ^$T) / $T
}
#put birthday-paradox 23, 10000;
@ -240,9 +240,11 @@ sub birthday-paradox(Int $n, Int $T) {
sub bisect(@a, $x, Int $low = 0, Int $high = @a.elems) {
return unless $low < $high;
my $mid = ($low + $high) div 2;
my $cmp = @a[$mid] cmp $x;
return $mid unless $cmp;
$cmp ~~ More ?? bisect @a, $x, $low, $mid !! bisect @a, $x, $mid+1, $high
given @a[$mid] cmp $x {
when Less { bisect @a, $x, $mid + 1, $high }
when Same { $mid }
when More { bisect @a, $x, $low, $mid }
}
}
# Exercise 9.11
@ -293,4 +295,4 @@ sub rotations {
}
@result
}
#.put for rotations;
.put for rotations;