开始计概A下半学期。
This commit is contained in:
1 parent
0cfdc8499c
commit
38e97654e1
31 files changed
+2144
-110
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
std::size_t calc_digits(std::string num) {
|
||||
if (num == "0") { return 1; }
|
||||
std::size_t ans = num.size(), i = 0;
|
||||
while (num[i] == '0') {
|
||||
i++;
|
||||
ans--;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::string num;
|
||||
std::cin >> num;
|
||||
std::cout << calc_digits(num) << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
constexpr std::size_t MAX_N = 1001;
|
||||
int students_amount, task_per_student, total_days;
|
||||
std::array<std::array<bool, MAX_N>, MAX_N> arrangements;
|
||||
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin >> students_amount >> task_per_student >> total_days;
|
||||
for (int _ = 0; _ < students_amount; _++) {
|
||||
for (int i = 0; i < task_per_student; i++) {
|
||||
int day;
|
||||
std::cin >> day;
|
||||
arrangements[day][i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
for (int i = 1; i <= total_days; i++) {
|
||||
if (!first) { std::cout << ' '; }
|
||||
std::cout << std::count(arrangements[i].begin(), arrangements[i].end(), true);
|
||||
first = false;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct Patient {
|
||||
int reservation_order = -1;
|
||||
std::string id;
|
||||
int age = -1;
|
||||
|
||||
bool operator<(const Patient& other) const {
|
||||
if (age < 60 && other.age >= 60) { return !(other < *this); }
|
||||
if (age >= 60) {
|
||||
if (other.age < 60) { return true; }
|
||||
if (age == other.age) { return reservation_order < other.reservation_order; }
|
||||
return age > other.age;
|
||||
}
|
||||
return reservation_order < other.reservation_order;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
std::vector<Patient> patients(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
std::cin >> patients[i].id >> patients[i].age;
|
||||
patients[i].reservation_order = i;
|
||||
}
|
||||
std::sort(patients.begin(), patients.end());
|
||||
for (const auto& [reservation_order, id, age] : patients) {
|
||||
std::cout << id << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 特别处理有一个杆子超级长?
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
|
||||
std::vector<int> half_lengths;
|
||||
half_lengths.reserve(2 * n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int length, flag_pos;
|
||||
std::cin >> length >> flag_pos;
|
||||
half_lengths.push_back(length - flag_pos);
|
||||
half_lengths.push_back(flag_pos);
|
||||
}
|
||||
std::sort(half_lengths.begin(), half_lengths.end(), std::greater<>());
|
||||
|
||||
std::cout << half_lengths[0] + half_lengths[1] << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
|
||||
const std::unordered_map<std::string, int> TYPE_NAME_PRIORITIES = {
|
||||
{"bool", 0},
|
||||
{"char", 1},
|
||||
{"int", 2},
|
||||
{"longlong", 4},
|
||||
{"float", 99},
|
||||
{"double", 100},
|
||||
};
|
||||
|
||||
class Type : public std::string {
|
||||
public:
|
||||
using std::string::string;
|
||||
|
||||
bool operator<(const Type& other) const {
|
||||
if (empty()) { return true; }
|
||||
return TYPE_NAME_PRIORITIES.at(*this) < TYPE_NAME_PRIORITIES.at(other);
|
||||
}
|
||||
};
|
||||
|
||||
void run() {
|
||||
Type max_type, current_type;
|
||||
std::string line;
|
||||
std::cin >> line;
|
||||
auto comma_pos = line.rfind(',');
|
||||
if (comma_pos != std::string::npos) {
|
||||
line.erase(0, comma_pos + 1);
|
||||
}
|
||||
for (char c : line) {
|
||||
if (!std::isalpha(c)) {
|
||||
std::clog << current_type << c << std::endl;
|
||||
if (c == ',') {
|
||||
max_type.clear();
|
||||
} else {
|
||||
if (max_type < Type("int")) { max_type = "int"; }
|
||||
max_type = std::max(max_type, current_type);
|
||||
}
|
||||
current_type.clear();
|
||||
} else {
|
||||
current_type += c;
|
||||
}
|
||||
}
|
||||
max_type = std::max(max_type, current_type);
|
||||
std::cout << max_type << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
int n;
|
||||
std::cin >> n;
|
||||
while (n--) { run(); }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
bool validate_arithmetic(const std::vector<bool>& bucket) {
|
||||
if (bucket.size() <= 1) { return false; }
|
||||
int previous_idx = -1, distance = -1;
|
||||
for (int i = 0; i < bucket.size(); i++) {
|
||||
if (!bucket[i]) { continue; }
|
||||
if (previous_idx == -1) {
|
||||
previous_idx = i;
|
||||
continue;
|
||||
}
|
||||
if (distance == -1) {
|
||||
distance = i - previous_idx;
|
||||
}
|
||||
if (i - previous_idx != distance) {
|
||||
return false;
|
||||
}
|
||||
previous_idx = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int clac_ans(const std::vector<int>& nums) {
|
||||
if (nums.size() == 1) { return 0; }
|
||||
std::vector<bool> bucket_begin(nums.size(), false);
|
||||
std::vector<bool> bucket_end(nums.size(), true);
|
||||
|
||||
int ans = 0;
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
bucket_begin[nums[i]] = true;
|
||||
bucket_end[nums[i]] = false;
|
||||
if (validate_arithmetic(bucket_begin) && validate_arithmetic(bucket_end)) {
|
||||
ans++;
|
||||
std::clog << i << std::endl;
|
||||
}
|
||||
}
|
||||
return ans - 1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
while (std::cin >> n) {
|
||||
std::vector<int> nums(n);
|
||||
for (int i = 0; i < n; i++) { std::cin >> nums[i], nums[i]--; }
|
||||
std::cout << clac_ans(nums) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
long long calc_min_ops(long long a, long long b) {
|
||||
if (a > b) { return a - b; }
|
||||
long long div = b / a;
|
||||
auto multiply_times = static_cast<long long>(std::log2(div));
|
||||
a = a * std::pow(2, multiply_times);
|
||||
return std::min(multiply_times + b - a, multiply_times + 1 + (2 * a - b));
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
long long a, b;
|
||||
std::cin >> a >> b;
|
||||
std::cout << calc_min_ops(a, b) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
|
||||
constexpr int MAX_N = 1000001, MOD = 10000;
|
||||
|
||||
/// dp[0][i]: 长方形;dp[1][i]: 阶梯型,i 为短边长
|
||||
long long dp[2][MAX_N];
|
||||
|
||||
void init_dp() {
|
||||
dp[0][0] = 1;
|
||||
dp[0][1] = 1;
|
||||
dp[0][2] = 2;
|
||||
dp[1][0] = 0;
|
||||
dp[1][1] = 1;
|
||||
dp[1][2] = 2;
|
||||
for (int i = 3; i < MAX_N; i++) {
|
||||
dp[0][i] = (dp[0][i - 1] + dp[0][i - 2] + dp[1][i - 2] * 2) % MOD;
|
||||
dp[1][i] = (dp[0][i - 1] + dp[1][i - 1]) % MOD;
|
||||
}
|
||||
}
|
||||
|
||||
void log_dp(int n) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
std::clog << dp[0][i] << ' ';
|
||||
}
|
||||
std::clog << std::endl;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
std::clog << dp[1][i] << ' ';
|
||||
}
|
||||
std::clog << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
init_dp();
|
||||
int n;
|
||||
std::cin >> n;
|
||||
std::cout << dp[0][n] % MOD << std::endl;;
|
||||
log_dp(n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
constexpr int char_to_digit(char c) {
|
||||
if (c >= '0' && c <= '9') { return static_cast<short>(c - '0'); }
|
||||
if (c >= 'A' && c <= 'Z') { return static_cast<short>(c - 'A' + 10); }
|
||||
throw std::invalid_argument("Invalid char as digit");
|
||||
}
|
||||
|
||||
constexpr char digit_to_char(int digit) {
|
||||
if (digit >= 0 && digit <= 9) { return static_cast<char>('0' + digit); }
|
||||
return static_cast<char>('A' + digit - 10);
|
||||
}
|
||||
|
||||
class BigFloat {
|
||||
public:
|
||||
std::array<std::vector<int>, 2> digit_vectors;
|
||||
bool negative = false;
|
||||
unsigned short base = 10;
|
||||
|
||||
explicit BigFloat(std::string s, unsigned short base = 10) : base(base) {
|
||||
int i = 0;
|
||||
if (s[0] == '-') { negative = true, i++; }
|
||||
for (; i < s.size() && s[i] != '.'; i++) { digit_vectors[0].push_back(char_to_digit(s[i])); }
|
||||
std::reverse(digit_vectors[0].begin(), digit_vectors[0].end());
|
||||
i++;
|
||||
for (; i < s.size(); i++) { digit_vectors[1].push_back(char_to_digit(s[i])); }
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
digit_vectors[0].push_back(0);
|
||||
digit_vectors[1].push_back(0);
|
||||
for (int i = static_cast<int>(digit_vectors[1].size() - 2); i >= 0; i--) {
|
||||
if (digit_vectors[1][i + 1] >= base) {
|
||||
digit_vectors[1][i] += digit_vectors[1][i + 1] / base;
|
||||
digit_vectors[1][i + 1] %= base;
|
||||
}
|
||||
if (digit_vectors[1][i + 1] < 0) {
|
||||
int borrowed = -(digit_vectors[1][i + 1] + 1) / base + 1;
|
||||
digit_vectors[1][i] -= borrowed;
|
||||
digit_vectors[1][i + 1] += base * borrowed;
|
||||
}
|
||||
}
|
||||
if (digit_vectors[1][0] >= base) {
|
||||
digit_vectors[0][0] += digit_vectors[1][0] / base;
|
||||
digit_vectors[1][0] %= base;
|
||||
}
|
||||
if (digit_vectors[1][0] < 0) {
|
||||
int borrowed = -(digit_vectors[1][0] + 1) / base + 1;
|
||||
digit_vectors[0][0] -= borrowed;
|
||||
digit_vectors[1][0] += base * borrowed;
|
||||
}
|
||||
for (int i = 1; i < digit_vectors[0].size(); i++) {
|
||||
if (digit_vectors[0][i - 1] >= base) {
|
||||
digit_vectors[0][i] += digit_vectors[0][i - 1] / base;
|
||||
digit_vectors[0][i - 1] %= base;
|
||||
}
|
||||
if (digit_vectors[0][i - 1] < 0) {
|
||||
int borrowed = -(digit_vectors[0][i - 1] + 1) / base + 1;
|
||||
digit_vectors[0][i] -= borrowed;
|
||||
digit_vectors[0][i - 1] += base * borrowed;
|
||||
}
|
||||
}
|
||||
|
||||
if (digit_vectors[0][digit_vectors[0].size() - 1] < 0) {
|
||||
// digit_vectors[0][digit_vectors[0].size() - 1] = -digit_vectors[0][digit_vectors[0].size() - 1];
|
||||
negative = !negative;
|
||||
for (auto& digits : digit_vectors) {
|
||||
for (auto& digit : digits) { digit = -digit; }
|
||||
}
|
||||
normalize();
|
||||
}
|
||||
|
||||
for (auto& digits : digit_vectors) {
|
||||
while (!digits.empty() && digits.back() == 0) { digits.pop_back(); }
|
||||
}
|
||||
if (digit_vectors[0].size() + digit_vectors[1].size() == 0) {
|
||||
digit_vectors[0].push_back(0);
|
||||
negative = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string() {
|
||||
normalize();
|
||||
std::string s;
|
||||
for (auto digit : digit_vectors[0]) { s += digit_to_char(digit); }
|
||||
if (negative) { s += '-'; }
|
||||
std::reverse(s.begin(), s.end());
|
||||
if (digit_vectors[1].empty()) { return s; }
|
||||
s += '.';
|
||||
for (auto digit : digit_vectors[1]) { s += digit_to_char(digit); }
|
||||
return s;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, BigFloat big_float) {
|
||||
return os << big_float.to_string();
|
||||
}
|
||||
|
||||
static void align(BigFloat& a, BigFloat& b) {
|
||||
for (auto part : {0, 1}) {
|
||||
if (a.digit_vectors[part].size() < b.digit_vectors[part].size()) {
|
||||
a.digit_vectors[part].resize(b.digit_vectors[part].size());
|
||||
} else if (b.digit_vectors[part].size() < a.digit_vectors[part].size()) {
|
||||
b.digit_vectors[part].resize(a.digit_vectors[part].size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BigFloat operator-() const {
|
||||
BigFloat result = *this;
|
||||
result.negative = !result.negative;
|
||||
return result;
|
||||
}
|
||||
|
||||
BigFloat& operator+=(BigFloat other) {
|
||||
if ((negative && !other.negative) || (!negative && other.negative)) { return *this -= -other; }
|
||||
align(*this, other);
|
||||
for (auto part : {0, 1}) {
|
||||
for (int i = 0; i < digit_vectors[part].size(); i++) {
|
||||
digit_vectors[part][i] += other.digit_vectors[part][i];
|
||||
}
|
||||
}
|
||||
normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
BigFloat& operator-=(BigFloat other) {
|
||||
if ((negative && !other.negative) || (!negative && other.negative)) { return *this += -other; }
|
||||
align(*this, other);
|
||||
for (auto part : {0, 1}) {
|
||||
for (int i = 0; i < digit_vectors[part].size(); i++) {
|
||||
digit_vectors[part][i] -= other.digit_vectors[part][i];
|
||||
}
|
||||
}
|
||||
normalize();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int cases;
|
||||
std::cin >> cases;
|
||||
while (cases--) {
|
||||
unsigned short base;
|
||||
std::string s1, s2;
|
||||
std::cin >> base >> s1 >> s2;
|
||||
|
||||
BigFloat number1(s1, base), number2(s2, base);
|
||||
std::clog << number1 << ' ' << number2 << std::endl;
|
||||
number1 -= number2;
|
||||
std::cout << number1 << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
constexpr int MAX_N = 31;
|
||||
|
||||
int dp[MAX_N];
|
||||
|
||||
void init_dp() {
|
||||
dp[0] = 1;
|
||||
dp[1] = 1;
|
||||
for (int i = 2; i < MAX_N; i++) {
|
||||
dp[i] = dp[i - 1] + dp[i - 2];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
init_dp();
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
std::cout << dp[n] << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
|
||||
long long gcd(long long a, long long b) {
|
||||
if (a < b) { return gcd(b, a); }
|
||||
if (b == 1) { return 1; }
|
||||
if (b == 0) { return a; }
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
long long lcm(long long a, long long b) {
|
||||
return a / gcd(a, b) * b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
char temp_comma;
|
||||
long long a, b;
|
||||
std::cin >> a >> temp_comma >> b;
|
||||
std::clog << gcd(a, b) << std::endl;
|
||||
std::cout << lcm(a, b) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
|
||||
bool is_palindromic(std::string s) {
|
||||
if (s.size() == 1) { return true; }
|
||||
for (int i = 0; i <= (s.size() - 2) / 2; i++) {
|
||||
if (s[i] != s[s.size() - i - 1]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::string s;
|
||||
std::cin >> s;
|
||||
std::cout << (is_palindromic(s) ? "yes" : "no") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
void print_kakutani_process(int n) {
|
||||
while (n != 1) {
|
||||
if (n % 2 == 0) {
|
||||
std::cout << n << "/2=" << (n /= 2) << std::endl;
|
||||
} else {
|
||||
std::cout << n << "*3+1=" << (n *= 3, n += 1) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::cin >> n;
|
||||
print_kakutani_process(n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#include <any>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using Grid = std::vector<std::vector<int>>;
|
||||
|
||||
class Vector2 {
|
||||
public:
|
||||
int x, y;
|
||||
constexpr explicit Vector2(const int x = 0, const int y = 0) : x(x), y(y) {}
|
||||
constexpr bool operator==(const Vector2 other) const { return x == other.x && y == other.y; }
|
||||
constexpr Vector2 operator+(const Vector2 other) const { return Vector2(x + other.x, y + other.y); }
|
||||
};
|
||||
|
||||
constexpr Vector2 DIRS[4] = {Vector2(0, 1), Vector2(1, 0), Vector2(0, -1), Vector2(-1, 0)};
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) {
|
||||
for (auto elem : vector) { os << elem << ' '; }
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void log_grid(const std::vector<std::vector<T>>& grid, const std::string& prefix = "") {
|
||||
for (auto line : grid) {
|
||||
std::clog << prefix << ' ' << line << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Grid get_init_grid(int r, int c) {
|
||||
Grid grid = std::vector(r + 2, std::vector(c + 2, 0));
|
||||
std::fill(grid[0].begin(), grid[0].end(), 1);
|
||||
std::fill(grid[grid.size() - 1].begin(), grid[grid.size() - 1].end(), 1);
|
||||
for (int j = 1; j <= r; j++) {
|
||||
grid[j][0] = grid[j][c + 1] = 1;
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
Grid input_grid() {
|
||||
int r, c;
|
||||
std::cin >> r >> c;
|
||||
Grid grid = get_init_grid(r, c);
|
||||
for (int i = 1; i <= r; i++) {
|
||||
for (int j = 1; j <= c; j++) {
|
||||
std::cin >> grid[i][j];
|
||||
}
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
bool verify_reachability(const Grid& grid,
|
||||
const Vector2 end_pos,
|
||||
Vector2 pos,
|
||||
std::vector<std::vector<bool>>& visited) {
|
||||
if (pos == end_pos) { return true; }
|
||||
if (grid[pos.x][pos.y] == 1) { return false; }
|
||||
if (visited[pos.x][pos.y]) { return false; }
|
||||
visited[pos.x][pos.y] = true;
|
||||
// log_grid(visited);
|
||||
for (const auto dir : DIRS) {
|
||||
if (verify_reachability(grid, end_pos, pos + dir, visited)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool verify_reachability(const Grid& grid) {
|
||||
Vector2 start_pos, end_pos;
|
||||
for (int i = 0; i < grid.size(); i++) {
|
||||
for (int j = 0; j < grid[0].size(); j++) {
|
||||
if (grid[i][j] == 2) { start_pos = Vector2(i, j); }
|
||||
if (grid[i][j] == 3) { end_pos = Vector2(i, j); }
|
||||
}
|
||||
}
|
||||
|
||||
std::vector visited(grid.size(), std::vector(grid[0].size(), false));
|
||||
return verify_reachability(grid, end_pos, start_pos, visited);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cout << (verify_reachability(input_grid()) ? "Yes" : "No") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
|
||||
constexpr int MAX_N = 1e6;
|
||||
|
||||
double dp[MAX_N + 1];
|
||||
|
||||
void init_dp(int x) {
|
||||
dp[0] = 1, dp[1] = x;
|
||||
for (int i = 2; i < MAX_N; i++) {
|
||||
dp[i] = ((2 * i - 1) * x * dp[i - 1] - (i - 1) * dp[i - 2]) / i;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int n, x;
|
||||
std::cin >> n >> x;
|
||||
init_dp(x);
|
||||
std::cout << dp[n] << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user