-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Certseeds/dev for v0.8.4
prepare for v0.8.4
- Loading branch information
Showing
75 changed files
with
2,470 additions
and
19 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,61 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <unordered_map> | ||
|
||
using namespace std; | ||
|
||
bool check_value(unordered_map<int32_t, int32_t> umap, vector<int32_t> vec1, double value); | ||
|
||
int main() { | ||
int32_t n; | ||
cin >> n; | ||
unordered_map<int32_t, int32_t> value_max; | ||
int32_t max_v = INT32_MIN / 2; | ||
for (int32_t i = 0; i < n; ++i) { | ||
int32_t a; | ||
int32_t b; | ||
cin >> a >> b; | ||
max_v = std::max(max_v, std::max(a, b)); | ||
value_max[a] = std::max(value_max[a], b); | ||
} | ||
vector<int32_t> value1; | ||
value1.reserve(value_max.size()); | ||
for (const auto &i: value_max) { | ||
value1.push_back(i.first); | ||
} | ||
std::sort(value1.begin(), value1.end(), std::less<int32_t>()); | ||
int32_t begin = 0; | ||
int32_t end = max_v * 2; | ||
int32_t middle = 0; | ||
while (begin < end) { | ||
middle = (end - begin) / 2 + begin; | ||
bool temp = check_value(value_max, value1, middle); | ||
cout << middle << " " << temp << endl; | ||
if (temp) { | ||
begin = middle + 1; | ||
} else { | ||
end = middle; | ||
} | ||
} | ||
cout << middle / 2; | ||
return 0; | ||
} | ||
|
||
bool check_value(unordered_map<int32_t, int32_t> umap, vector<int32_t> vec1, double value) { | ||
for (int32_t i = vec1.size() - 1; i >= 0; i--) { | ||
auto order = std::lower_bound(vec1.begin(), vec1.end(), value - vec1[i]); | ||
if (order == vec1.end()) { | ||
continue; | ||
} | ||
if (i != order - vec1.begin() && umap[vec1[i]] + umap[vec1[order - vec1.begin()]] >= value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
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,8 @@ | ||
cmake_minimum_required(VERSION 3.16.6) | ||
set(PROJECT_DAY 20200415) | ||
project(${PROJECT_NAME}_${PROJECT_DAY}) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
|
||
add_executable(${PROJECT_NAME}_${PROJECT_DAY} ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_DAY}.cpp) |
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,4 @@ | ||
20200415 code test | ||
|
||
company: [encryet company name](./company.gpg) | ||
|
Binary file not shown.
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,60 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
#include <cstdint> | ||
#include <iostream> | ||
#include <queue> | ||
#include <algorithm> | ||
#include <array> | ||
|
||
static constexpr const std::array<const char *const, 5> command2{"PUSH", "TOP", "POP", "SIZE", "CLEAR"}; | ||
|
||
int32_t main() { | ||
size_t t{0}; | ||
std::cin >> t; | ||
for (size_t i{0}; i < t; ++i) { | ||
std::queue<int32_t> que; | ||
size_t q{0}; | ||
std::cin >> q; | ||
for (size_t j{0}; j < q; ++j) { | ||
std::string com; | ||
int number; | ||
std::cin >> com; | ||
switch (std::distance(command2.begin(), | ||
std::find(command2.begin(), command2.end(), com) | ||
)) { | ||
case 1: { | ||
std::cin >> number; | ||
que.push(number); | ||
break; | ||
} | ||
case 2: { | ||
if (que.empty()) { | ||
std::cout << -1 << std::endl; | ||
} else { | ||
std::cout << que.front() << std::endl; | ||
} | ||
break; | ||
} | ||
case 3: { | ||
if (que.empty()) { | ||
std::cout << -1 << std::endl; | ||
} else { | ||
que.pop(); | ||
} | ||
break; | ||
} | ||
case 4: { | ||
std::cout << que.size() << std::endl; | ||
break; | ||
} | ||
case 5: { | ||
que = std::queue<int32_t>(); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
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,57 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
#include <cstdint> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
int32_t main() { | ||
int32_t n{0}; | ||
std::cin >> n; | ||
std::vector<std::pair<int32_t, int32_t>> a; | ||
std::vector<std::pair<int32_t, int32_t>> b; | ||
for (int i{0}; i < n; ++i) { | ||
int x1{0}, x2{0}; | ||
std::cin >> x1 >> x2; | ||
a.emplace_back(x1, x2); | ||
} | ||
for (int i{0}; i < n; ++i) { | ||
int x1{0}, x2{0}; | ||
std::cin >> x1 >> x2; | ||
b.emplace_back(x1, x2); | ||
} | ||
std::sort(a.begin(), a.end()); | ||
std::sort(b.begin(), b.end()); | ||
double min_value = INT32_MAX / 2; | ||
struct compare { | ||
bool operator()(const std::pair<int, int> &value, | ||
const int &key) { | ||
return (value.first < key); | ||
} | ||
|
||
bool operator()(const int &key, | ||
const std::pair<int, int> &value) { | ||
return (key < value.first); | ||
} | ||
}; | ||
for (const auto &i: a) { | ||
const auto it = std::upper_bound(b.begin(), b.end(), | ||
i.first, compare()) - b.begin(); | ||
// int order = std::find(b.begin(), b.end(), a.at(j).first) - b.begin(); | ||
for (int l = 0; l < 16; ++l) { | ||
min_value = std::min( | ||
min_value, | ||
std::pow((i.first - b.at(std::min(it + l, static_cast<long>(b.size() - 1))).first), 2) + | ||
std::pow((i.second - b.at(std::min(it + l, static_cast<long>(b.size() - 1))).second), 2)); | ||
min_value = std::min( | ||
min_value, | ||
std::pow((i.first - b.at(std::max(it - l, static_cast<long>(0))).first), 2) + | ||
std::pow((i.second - b.at(std::max(it - l, static_cast<long>(0))).second), 2)); | ||
} | ||
} | ||
printf("%.3f", std::sqrt(min_value)); | ||
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,42 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
#include <cstdint> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <stack> | ||
|
||
inline void s1_to_s2(std::stack<int32_t> &s1, std::stack<int32_t> &s2) { | ||
while (!s1.empty()) { | ||
s2.push(s1.top()); | ||
s1.pop(); | ||
} | ||
} | ||
|
||
int32_t main() { | ||
int32_t n{0}; | ||
std::cin >> n; | ||
std::stack<int32_t> stack1, stack2; | ||
for (int i = 0; i < n; ++i) { | ||
std::string str; | ||
std::cin >> str; | ||
if ("add" == str) { | ||
int number; | ||
std::cin >> number; | ||
stack1.push(number); | ||
s1_to_s2(stack2, stack1); | ||
s1_to_s2(stack1, stack2); | ||
} else if ("poll" == str) { | ||
s1_to_s2(stack2, stack1); | ||
stack1.pop(); | ||
s1_to_s2(stack1, stack2); | ||
} else if ("peek" == str) { | ||
s1_to_s2(stack2, stack1); | ||
std::cout << stack1.top() << std::endl; | ||
s1_to_s2(stack1, stack2); | ||
} | ||
} | ||
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,39 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
#include <cstdint> | ||
#include <vector> | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <stack> | ||
|
||
int main() { | ||
uint32_t q{0}; | ||
std::cin >> q; | ||
for (uint32_t i{0}; i < q; ++i) { | ||
int64_t x{0}; | ||
int32_t k{0}; | ||
std::cin >> x >> k; | ||
int32_t times{0}; | ||
std::stack<int32_t> sta; | ||
while (x > 0) { | ||
sta.push(x & 1); | ||
x /= 2; | ||
times++; | ||
} | ||
if (k >= times) { | ||
std::cout << -1 << std::endl; | ||
continue; | ||
} | ||
uint64_t will_cout = 0; | ||
for (int32_t j{0}; j + 1 < k; ++j) { | ||
will_cout += sta.top(); | ||
sta.pop(); | ||
will_cout *= 2; | ||
} | ||
will_cout += sta.top(); | ||
//cout << times << endl; | ||
std::cout << will_cout << std::endl; | ||
} | ||
} |
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,13 @@ | ||
cmake_minimum_required(VERSION 3.16.6) | ||
set(PROJECT_DAY 20200426) | ||
project(${PROJECT_NAME}_${PROJECT_DAY}) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
|
||
|
||
set(dependencies "1st" "3rd" "4th" "5th") | ||
foreach (elementName IN LISTS dependencies) | ||
add_executable(${PROJECT_NAME}_${PROJECT_DAY}_${elementName} | ||
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_DAY}_${elementName}.cpp) | ||
endforeach () |
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,4 @@ | ||
20200426 code test | ||
|
||
company: [encryet company name](./company.gpg) | ||
|
Binary file not shown.
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,73 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
/* CS203_DSAA_template | ||
Copyright (C) 2020-2022 nanoseeds | ||
*/ | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <unordered_set> | ||
|
||
#ifdef CS203_DSAA_TEST_MACRO | ||
namespace fourth_20200511{ | ||
#endif | ||
|
||
using std::cin; | ||
using std::cout; | ||
using std::string; | ||
using std::vector; | ||
using std::unordered_set; | ||
static constexpr const char end{'\n'}; | ||
|
||
using num_t = int32_t; | ||
|
||
int main() { | ||
string init; | ||
int32_t number; | ||
cin >> init; | ||
cin >> number; | ||
int32_t command{0}; | ||
unordered_set<char> uset; | ||
int32_t first{0}; | ||
for (int32_t i{0}; i < number; ++i) { | ||
cin >> command; | ||
cin >> first; | ||
switch (command) { | ||
case 1: { | ||
char second; | ||
cin >> second; | ||
init[first - 1] = second; | ||
break; | ||
} | ||
case 2: { | ||
int32_t second; | ||
cin >> second; | ||
for (int j = first - 1; j < second; ++j) { | ||
uset.insert(init[j]); | ||
} | ||
cout << uset.size() << "\n"; | ||
uset.clear(); | ||
break; | ||
} | ||
default: { | ||
return -1; | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static const auto faster_streams = [] { | ||
srand(time(nullptr)); | ||
// use time to init the random seed | ||
std::ios::sync_with_stdio(false); | ||
std::istream::sync_with_stdio(false); | ||
std::ostream::sync_with_stdio(false); | ||
std::cin.tie(nullptr); | ||
std::cout.tie(nullptr); | ||
// 关闭c++风格输入输出 , 与C风格输入输出的同步,提高性能. | ||
return 0; | ||
}(); | ||
#ifdef CS203_DSAA_TEST_MACRO | ||
} | ||
#endif |
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,7 @@ | ||
abacaba | ||
5 | ||
2 1 4 | ||
1 4 b | ||
1 5 b | ||
2 4 6 | ||
2 1 7 |
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,3 @@ | ||
3 | ||
1 | ||
2 |
Oops, something went wrong.