From 4527ba6b440421484835f41277c85b008a3a552d Mon Sep 17 00:00:00 2001 From: RryLee Date: Thu, 25 Feb 2016 01:05:38 +0800 Subject: [PATCH] day two --- Implementation/1-angry-professor.php | 20 ++++++++ Implementation/10-the-grid-search.php | 54 ++++++++++++++++++++ Implementation/11-cavity-map.cpp | 35 +++++++++++++ Implementation/11-cavity-map.php | 23 +++++++++ Implementation/12-library-fine.cpp | 33 ++++++++++++ Implementation/12-library-fine.php | 21 ++++++++ Implementation/12-manasa-and-stones.cpp | 31 +++++++++++ Implementation/12-manasa-and-stones.php | 27 ++++++++++ Implementation/13-acm-icpc-team.php | 0 Implementation/2-sherlock-and-the-beast.cpp | 31 +++++++++++ Implementation/2-sherlock-and-the-beast.php | 19 +++++++ Implementation/3-utopian-tree.cpp | 24 +++++++++ Implementation/3-utopian-tree.php | 15 ++++++ Implementation/4-find-digits.cpp | 25 +++++++++ Implementation/4-find-digits.php | 42 +++++++++++++++ Implementation/5-sherlock-and-squares.cpp | 20 ++++++++ Implementation/5-sherlock-and-squares.php | 10 ++++ Implementation/6-service-lane.c | 33 ++++++++++++ Implementation/6-service-lane.cpp | 32 ++++++++++++ Implementation/6-service-lane.php | 13 +++++ Implementation/7-cut-the-sticks.cpp | 41 +++++++++++++++ Implementation/7-cut-the-sticks.php | 22 ++++++++ Implementation/8-chocolate-feast.c | 26 ++++++++++ Implementation/8-chocolate-feast.php | 18 +++++++ Implementation/9-caesar-cipher-1.c | 30 +++++++++++ Implementation/9-caesar-cipher-1.php | 6 +++ Implementation/a.out | Bin 0 -> 13200 bytes Warmup/6-staircase.php | 2 + 28 files changed, 653 insertions(+) create mode 100644 Implementation/1-angry-professor.php create mode 100644 Implementation/10-the-grid-search.php create mode 100644 Implementation/11-cavity-map.cpp create mode 100644 Implementation/11-cavity-map.php create mode 100644 Implementation/12-library-fine.cpp create mode 100644 Implementation/12-library-fine.php create mode 100644 Implementation/12-manasa-and-stones.cpp create mode 100644 Implementation/12-manasa-and-stones.php create mode 100644 Implementation/13-acm-icpc-team.php create mode 100644 Implementation/2-sherlock-and-the-beast.cpp create mode 100644 Implementation/2-sherlock-and-the-beast.php create mode 100644 Implementation/3-utopian-tree.cpp create mode 100644 Implementation/3-utopian-tree.php create mode 100644 Implementation/4-find-digits.cpp create mode 100644 Implementation/4-find-digits.php create mode 100644 Implementation/5-sherlock-and-squares.cpp create mode 100644 Implementation/5-sherlock-and-squares.php create mode 100644 Implementation/6-service-lane.c create mode 100644 Implementation/6-service-lane.cpp create mode 100755 Implementation/6-service-lane.php create mode 100644 Implementation/7-cut-the-sticks.cpp create mode 100644 Implementation/7-cut-the-sticks.php create mode 100644 Implementation/8-chocolate-feast.c create mode 100755 Implementation/8-chocolate-feast.php create mode 100644 Implementation/9-caesar-cipher-1.c create mode 100644 Implementation/9-caesar-cipher-1.php create mode 100755 Implementation/a.out diff --git a/Implementation/1-angry-professor.php b/Implementation/1-angry-professor.php new file mode 100644 index 0000000..b9f88d1 --- /dev/null +++ b/Implementation/1-angry-professor.php @@ -0,0 +1,20 @@ + $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; +} diff --git a/Implementation/11-cavity-map.cpp b/Implementation/11-cavity-map.cpp new file mode 100644 index 0000000..33c73a6 --- /dev/null +++ b/Implementation/11-cavity-map.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + vector 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; +} diff --git a/Implementation/11-cavity-map.php b/Implementation/11-cavity-map.php new file mode 100644 index 0000000..e9059ad --- /dev/null +++ b/Implementation/11-cavity-map.php @@ -0,0 +1,23 @@ + $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; +} diff --git a/Implementation/12-library-fine.cpp b/Implementation/12-library-fine.cpp new file mode 100644 index 0000000..e38bf76 --- /dev/null +++ b/Implementation/12-library-fine.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +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; +} diff --git a/Implementation/12-library-fine.php b/Implementation/12-library-fine.php new file mode 100644 index 0000000..a2de3a3 --- /dev/null +++ b/Implementation/12-library-fine.php @@ -0,0 +1,21 @@ + +#include +#include + +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 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; +} diff --git a/Implementation/12-manasa-and-stones.php b/Implementation/12-manasa-and-stones.php new file mode 100644 index 0000000..8a4f744 --- /dev/null +++ b/Implementation/12-manasa-and-stones.php @@ -0,0 +1,27 @@ + $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; +} diff --git a/Implementation/13-acm-icpc-team.php b/Implementation/13-acm-icpc-team.php new file mode 100644 index 0000000..e69de29 diff --git a/Implementation/2-sherlock-and-the-beast.cpp b/Implementation/2-sherlock-and-the-beast.cpp new file mode 100644 index 0000000..9234592 --- /dev/null +++ b/Implementation/2-sherlock-and-the-beast.cpp @@ -0,0 +1,31 @@ +// c++ faster than php +#include + +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; +} diff --git a/Implementation/2-sherlock-and-the-beast.php b/Implementation/2-sherlock-and-the-beast.php new file mode 100644 index 0000000..6241351 --- /dev/null +++ b/Implementation/2-sherlock-and-the-beast.php @@ -0,0 +1,19 @@ += 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; +} diff --git a/Implementation/3-utopian-tree.cpp b/Implementation/3-utopian-tree.cpp new file mode 100644 index 0000000..12914b3 --- /dev/null +++ b/Implementation/3-utopian-tree.cpp @@ -0,0 +1,24 @@ +#include + +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; +} diff --git a/Implementation/3-utopian-tree.php b/Implementation/3-utopian-tree.php new file mode 100644 index 0000000..1de0977 --- /dev/null +++ b/Implementation/3-utopian-tree.php @@ -0,0 +1,15 @@ + + +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; +} diff --git a/Implementation/4-find-digits.php b/Implementation/4-find-digits.php new file mode 100644 index 0000000..d2f1cf4 --- /dev/null +++ b/Implementation/4-find-digits.php @@ -0,0 +1,42 @@ + 0) { + $current_digit = $m % 10; + $m = (int) $m / 10; + if ($current_digit != 0 && $n % $current_digit == 0) { + $result ++; + } + } + + echo $result . PHP_EOL; +} diff --git a/Implementation/5-sherlock-and-squares.cpp b/Implementation/5-sherlock-and-squares.cpp new file mode 100644 index 0000000..a3c0839 --- /dev/null +++ b/Implementation/5-sherlock-and-squares.cpp @@ -0,0 +1,20 @@ +// ⌊b‾√⌋−⌈a‾√⌉+1 +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int t; + cin >> t; + while(t --) { + int a, b, result; + cin >> a >> b; + + result = floor(sqrt(b)) - ceil(sqrt(a)) + 1; + cout << result << endl; + } + + return 0; +} diff --git a/Implementation/5-sherlock-and-squares.php b/Implementation/5-sherlock-and-squares.php new file mode 100644 index 0000000..21c85f3 --- /dev/null +++ b/Implementation/5-sherlock-and-squares.php @@ -0,0 +1,10 @@ + + +int min(int a, int b) +{ + return a > b ? b : a; +} + +int main(int argc, char const *argv[]) +{ + int N, T; + scanf("%d %d", &N, &T); + int width[N]; + + for (int i = 0; i < N; i ++) { + scanf("%d", &width[i]); + } + + for (int i = 0; i < T; i ++) { + int l, r; + scanf("%d %d", &l, &r); + + int result = width[l]; + while(l <= r) { + result = min(result, width[l]); + l ++; + } + + printf("%d\n", result); + } + + return 0; +} diff --git a/Implementation/6-service-lane.cpp b/Implementation/6-service-lane.cpp new file mode 100644 index 0000000..b9aa902 --- /dev/null +++ b/Implementation/6-service-lane.cpp @@ -0,0 +1,32 @@ +// test#11 0.02s +#include +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int N, T; + cin >> N >> T; + + vector width(N); + for (int i = 0; i < N; i ++) { + cin >> width[i]; + } + + for (int i = 0; i < T; i ++) { + int l, r; + cin >> l >> r; + + int ans = width[l]; + while(l <= r) { + ans = min(ans, width[l]); + l ++; + } + + cout << ans << endl; + } + + return 0; +} diff --git a/Implementation/6-service-lane.php b/Implementation/6-service-lane.php new file mode 100755 index 0000000..f4d918b --- /dev/null +++ b/Implementation/6-service-lane.php @@ -0,0 +1,13 @@ + +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + vector arr(n); + for(int arr_i = 0;arr_i < n;arr_i++){ + cin >> arr[arr_i]; + } + + int mx = *max_element(arr.begin(), arr.end()); + while (mx > 0) { + int mn = mx; + int cuts = 0; + + for (int i = 0; i < n; ++i) + { + if (arr[i] > 0) { + mn = min(mn, arr[i]); + } + } + + for (int i = 0; i < n; ++i) + { + if (arr[i] > 0) { + cuts ++; + arr[i] -= mn; + } + } + + cout << cuts << endl; + mx = *max_element(arr.begin(), arr.end()); + } + + return 0; +} diff --git a/Implementation/7-cut-the-sticks.php b/Implementation/7-cut-the-sticks.php new file mode 100644 index 0000000..ee25a5f --- /dev/null +++ b/Implementation/7-cut-the-sticks.php @@ -0,0 +1,22 @@ + + +int main(){ + int t; + scanf("%d",&t); + for(int a0 = 0; a0 < t; a0++){ + int n; + int c; + int m; + scanf("%d %d %d",&n,&c,&m); + + int wrapper; + wrapper = n / c; + int count; + count = wrapper; + while (wrapper >= m) { + wrapper -= m; + count ++; + wrapper ++; + } + + printf("%d\n", count); + } + return 0; +} + diff --git a/Implementation/8-chocolate-feast.php b/Implementation/8-chocolate-feast.php new file mode 100755 index 0000000..95b8aac --- /dev/null +++ b/Implementation/8-chocolate-feast.php @@ -0,0 +1,18 @@ += $m) { + $wrappers -= $m; + $count ++; + $wrappers ++; + } + + echo $count . PHP_EOL; +} + diff --git a/Implementation/9-caesar-cipher-1.c b/Implementation/9-caesar-cipher-1.c new file mode 100644 index 0000000..346bd6e --- /dev/null +++ b/Implementation/9-caesar-cipher-1.c @@ -0,0 +1,30 @@ +#include +#include +#include + +int main(){ + int n; + scanf("%d",&n); + char* s = (char *)malloc(10240 * sizeof(char)); + scanf("%s",s); + int k; + scanf("%d",&k); + + int i = 0; + char ch; + while (s[i] != '\0') { + if (s[i] >= 'a' && s[i] <= 'z') { + ch = 'a'; + s[i] = ch + (s[i] - ch + k) % 26; + } else if (s[i] >= 'A' && s[i] <= 'Z') { + ch = 'A'; + s[i] = ch + (s[i] - ch + k) % 26; + } + + i ++; + } + + printf("%s\n", s); + + return 0; +} diff --git a/Implementation/9-caesar-cipher-1.php b/Implementation/9-caesar-cipher-1.php new file mode 100644 index 0000000..ca3a076 --- /dev/null +++ b/Implementation/9-caesar-cipher-1.php @@ -0,0 +1,6 @@ +* zMRWwELG{u=x4{-BP3okfb$@Iy?W>zK>aMIQ(>}_ykBV(5LVyy=5C{et>&SlR-h1q4 z$3X~b|K(cG=bqm^=iGbGz3;yJ?mPDe!@Haghv4KCI|XsAm3|4Se<3_KN>*cy;tJsx zYsDH-0i+z4UzQM6Ii_>kG}9_A=K?Lm)#y|}qth=lOh2q(!IWD_l&;`WEv`m2N*%-Cc20 zU!r^a)|>ibwS9?!^l|b`|cNhK=R9R@wj0II)$T5Vt_^R>y^$;!9Ry7Un)`k-Vz1t z7QxR0zp{k6UHxP#iAek7>(I>VVe8<2M5fQ6-ipADa>0Bnr-p@iIf#jHuptRsd!45p^n?k zSUjoWj@z311_$CDk?y{@Dl1)bXS5illQ46h*@NHB1 z&Q5a+a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