diff --git a/Search/1-sherlock-and-array.cpp b/Search/1-sherlock-and-array.cpp new file mode 100644 index 0000000..096a5d5 --- /dev/null +++ b/Search/1-sherlock-and-array.cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int T; + cin >> T; + while (T --) { + int N; + cin >> N; + int A[N]; + int sum = 0; + for (int i = 0; i < N; i ++) { + scanf("%d", &A[i]); + sum += A[i]; + } + + int right = sum; + bool exists = false; + + for (int i = 0; i < N; i ++) { + int left = sum - right; + right -= A[i]; + + if (left == right) { + exists = true; + break; + } + } + + if (exists) { + cout << "YES" << endl; + } else { + cout << "NO" << endl; + } + } + + return 0; +} diff --git a/Search/1-sherlock-and-array.php b/Search/1-sherlock-and-array.php new file mode 100644 index 0000000..14edeb4 --- /dev/null +++ b/Search/1-sherlock-and-array.php @@ -0,0 +1,31 @@ + +#include +#include + +using namespace std; + +typedef unsigned long long ull; + +ull find_result(const vector &v, ull m) { + vector prefix; + set s; + + // get prefix array + size_t v_size = v.size(); + ull tmp = 0; + for (size_t i=0; i v; + ull n, m, tmp; + for (int i=0; i 0); + $msum = array(-1 => 0); + $midx = array(); + $midx[0][] = -1; + $max = 0; + for ($i=0; $i < $n; $i++) { + $psum[$i] = $psum[$i - 1] + $nums[$i]; + $msum[$i] = $psum[$i] % $m; + $midx[$msum[$i]][] = $i; + if ($msum[$i] > $max) + $max = $msum[$i]; + } + // print_r($psum); + // print_r($msum); + + sort($msum); + for ($i=1; $i <= $n; $i++) { + $sum1 = $msum[$i - 1]; + $sum2 = $msum[$i]; + // echo "sum1:$sum1, sum2:$sum2\n"; + foreach ($midx[$sum1] as $p1) { + foreach ($midx[$sum2] as $p2) { + if ($p1 > $p2) { + $d = $sum1 - $sum2; + if ($d < 0 && $m + $d > $max) { + $max = $m + $d; + } + } + } + } + } + + echo $max . "\n"; +} diff --git a/Search/4-missing-numbers.cpp b/Search/4-missing-numbers.cpp new file mode 100644 index 0000000..f7f517d --- /dev/null +++ b/Search/4-missing-numbers.cpp @@ -0,0 +1,33 @@ +#include +#include + +typedef unsigned long ul; + +using namespace std; + +int main(int argc, char const *argv[]) +{ + ul n, m; + cin >> n; + int times[10005] = {0}; + for (ul i = 0; i < n; i ++) { + int temp; + scanf("%d", &temp); + times[temp] --; + } + + cin >> m; + for (ul i = 0; i < m; i ++) { + int temp; + scanf("%d", &temp); + times[temp] ++; + } + + for (int i = 0; i < 10005; i ++) { + if (times[i] >= 1) { + cout << i << " "; + } + } + + return 0; +} diff --git a/Search/4-missing-numbers.php b/Search/4-missing-numbers.php new file mode 100644 index 0000000..e9f9bf1 --- /dev/null +++ b/Search/4-missing-numbers.php @@ -0,0 +1,6 @@ +