-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RryLee
committed
Feb 24, 2016
1 parent
2dc5bcf
commit 4527ba6
Showing
28 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
$handle = fopen("php://stdin", "r"); | ||
fscanf($handle, "%d", $t); | ||
|
||
for ($a0 = 0; $a0 < $t; $a0 ++) { | ||
fscanf($handle, "%d %d", $n, $k); | ||
$a_temp = fgets($handle); | ||
$a = explode(" ", $a_temp); | ||
array_walk($a, 'intval'); | ||
|
||
if (count(array_filter($a, function($temp) { | ||
return $temp <= 0; | ||
})) < $k) { | ||
echo "YES" . PHP_EOL; | ||
} else { | ||
echo "NO" . PHP_EOL; | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
$handle = fopen ("php://stdin", "r"); | ||
fscanf($handle, "%d", $t); | ||
|
||
for ($a0 = 0; $a0 < $t; $a0++) { | ||
$big = array(); | ||
$small = array(); | ||
|
||
fscanf($handle, "%d %d", $R, $C); | ||
for ($big_i = 0; $big_i < $R; $big_i++) { | ||
fscanf($handle, "%s", $big[]); | ||
} | ||
|
||
fscanf($handle, "%d %d", $r, $c); | ||
for ($small_i = 0; $small_i < $r; $small_i++) { | ||
fscanf($handle, "%s", $small[]); | ||
} | ||
|
||
echo gridExists($big, $small) ? "YES\n" : "NO\n"; | ||
} | ||
|
||
function gridExists(array $big, array $small) { | ||
$exists = false; | ||
$match = []; | ||
|
||
foreach ($big as $key => $bigLine) { | ||
if ($exists) break; | ||
|
||
$start = 0; | ||
|
||
while (($position = strpos($bigLine, $small[0], $start)) !== false) { | ||
if ($exists) break; | ||
|
||
$match = [$key, $position]; | ||
// $start += strlen($small[0]); | ||
|
||
for ($i = 1, $j = $match[0] + 1; $i < count($small); $i ++, $j ++) { | ||
$position = strpos($big[$j], $small[$i], $start); | ||
|
||
if ($position === false || $position !== $match[1]) { | ||
$exists = false; | ||
break; | ||
} else { | ||
$exists = true; | ||
} | ||
} | ||
|
||
$start ++; | ||
} | ||
} | ||
|
||
return $exists; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cin >> n; | ||
vector<string> grid(n); | ||
for(int grid_i = 0;grid_i < n;grid_i++){ | ||
cin >> grid[grid_i]; | ||
} | ||
|
||
for (int i = 1; i < n - 1; ++i) | ||
{ | ||
for (int j = 1; j < n - 1; ++j) | ||
{ | ||
if (grid[i][j] > grid[i][j + 1] && | ||
grid[i][j] > grid[i][j - 1] && | ||
grid[i][j] > grid[i + 1][j] && | ||
grid[i][j] > grid[i - 1][j]) { | ||
grid[i][j] = 'X'; | ||
} | ||
} | ||
} | ||
|
||
for(int grid_i = 0;grid_i < n;grid_i++){ | ||
cout << grid[grid_i] << endl; | ||
} | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
$handle = fopen ("php://stdin","r"); | ||
fscanf($handle,"%d",$n); | ||
$grid = array(); | ||
for($grid_i = 0; $grid_i < $n; $grid_i++) { | ||
fscanf($handle,"%s",$grid[]); | ||
} | ||
|
||
for ($i = 1; $i < $n - 1; $i++) { | ||
for ($j = 1; $j < $n - 1; $j++) { | ||
if ($grid[$i][$j] > $grid[$i][$j + 1] && | ||
$grid[$i][$j] > $grid[$i][$j - 1] && | ||
$grid[$i][$j] > $grid[$i + 1][$j] && | ||
$grid[$i][$j] > $grid[$i - 1][$j]) { | ||
$grid[$i][$j] = 'X'; | ||
} | ||
} | ||
} | ||
|
||
foreach ($grid as $g) { | ||
print $g . PHP_EOL; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
int main(){ | ||
int d1; | ||
int m1; | ||
int y1; | ||
cin >> d1 >> m1 >> y1; | ||
int d2; | ||
int m2; | ||
int y2; | ||
cin >> d2 >> m2 >> y2; | ||
|
||
int fine = 0; | ||
|
||
if (y1 == y2) { | ||
if (m1 > m2) { | ||
fine = (m1 - m2) * 500; | ||
} else if (d1 > d2 && m1 == m2) { | ||
fine = (d1 - d2) * 15; | ||
} | ||
} else if (y1 > y2) { | ||
fine = 10000; | ||
} | ||
|
||
cout << fine << endl; | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
$handle = fopen ("php://stdin","r"); | ||
fscanf($handle,"%d %d %d",$d1,$m1,$y1); | ||
fscanf($handle,"%d %d %d",$d2,$m2,$y2); | ||
|
||
$fine = null; | ||
|
||
if ($y1 !== $y2) { | ||
$fine = null ? $fine : 1000; | ||
} | ||
|
||
if ($m1 !== $m2) { | ||
$fine = null ? $fine : 500 * abs($m1 - $m2); | ||
} | ||
|
||
if ($d1 !== $d2) { | ||
$fine = null ? $fine : 15 * abs($d1 - $d2); | ||
} | ||
|
||
echo $fine . PHP_EOL; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <set> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int t; | ||
cin >> t; | ||
while (t --) { | ||
long long a, b, n, i; | ||
long long int c, d; | ||
set <int> x; | ||
cin >> n >> c >> d; | ||
a = max(c, d); | ||
b = min(c, d); | ||
|
||
for (int i = 0; i < n; ++i) | ||
{ | ||
x.insert(i * b + (n - 1 - i) * a); | ||
} | ||
|
||
for (auto it = x.begin(); it != x.end(); it ++) { | ||
cout << *it << " "; | ||
} | ||
|
||
cout << endl; | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
$handle = fopen("php://stdin", "r"); | ||
|
||
fscanf($handle, "%d", $t); | ||
|
||
for ($a0=0; $a0 < $t; $a0++) { | ||
fscanf($handle, "%d", $n); | ||
fscanf($handle, "%d", $a); | ||
fscanf($handle, "%d", $b); | ||
|
||
if ($a > $b) { | ||
$temp = $a; | ||
$a = $b; | ||
$b = $temp; | ||
} | ||
|
||
$result = []; | ||
for ($i=0; $i <= $n - 1; $i++) { | ||
$temp = ($n - 1 - $i) * $a + $i * $b; | ||
if (! in_array($temp, $result)) { | ||
$result[] = $temp; | ||
} | ||
} | ||
|
||
echo implode(" ", $result) . PHP_EOL; | ||
} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// c++ faster than php | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int t; | ||
cin >> t; | ||
while (t --) { | ||
int n; | ||
cin >> n; | ||
|
||
int i, k; | ||
string s; | ||
for (i = n; i >= 0; i -= 5) { | ||
if (i % 3 == 0 && (n - i) % 5 == 0) { | ||
s = ""; | ||
for (k = 0; k < i; k ++) | ||
s += '5'; | ||
for (k = 0; k < n - i; k ++) | ||
s += '3'; | ||
break; | ||
} | ||
} | ||
if(s == "") | ||
cout << "-1" << endl; | ||
else | ||
cout << s << endl; | ||
} | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
$handle = fopen ("php://stdin","r"); | ||
fscanf($handle,"%d",$t); | ||
for($a0 = 0; $a0 < $t; $a0++){ | ||
fscanf($handle,"%d",$n); | ||
|
||
$found = false; | ||
|
||
for ($i = $n ; $i >= 0; $i -= 5) { | ||
if (($n - $i) % 5 == 0 && ($i % 3 == 0)) { | ||
echo str_repeat('5', $i) . str_repeat('3', $n - $i) . PHP_EOL; | ||
$found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (! $found) echo '-1' . PHP_EOL; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int T, N, i; | ||
cin >> T; | ||
while(T --) { | ||
cin >> N; | ||
long long int s = 1; | ||
for (i = 1; i <= N; i ++) { | ||
if (i % 2 == 0) { | ||
s ++; | ||
} else { | ||
s *= 2; | ||
} | ||
} | ||
|
||
cout << s << endl; | ||
} | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
$handle = fopen ("php://stdin","r"); | ||
fscanf($handle,"%d",$t); | ||
for($a0 = 0; $a0 < $t; $a0++){ | ||
fscanf($handle,"%d",$n); | ||
|
||
if ($n % 2 == 0) | ||
$height = (pow(2, (int) ($n / 2)) - 1) * 2 + 1; | ||
else | ||
$height = (pow(2, (int) ($n / 2) + 1) - 1) * 2; | ||
|
||
echo $height . PHP_EOL; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
int t; | ||
cin >> t; | ||
for(int a0 = 0; a0 < t; a0++){ | ||
int n, m; | ||
int digit_count = 0; | ||
cin >> n; | ||
m = n; | ||
|
||
while(m > 0) { | ||
int curr_digit = m % 10; | ||
m /= 10; | ||
if (curr_digit != 0 && n % curr_digit == 0) { | ||
digit_count ++; | ||
} | ||
} | ||
|
||
cout << digit_count << endl; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.