some programs!
This commit is contained in:
1 parent
5d30e847c1
commit
ed054247d5
32 files changed
+1882
-149
No files matched your search
@@ -0,0 +1,76 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
long long gcd(long long x, long long y) {
|
||||
if (x < y) swap(x, y);
|
||||
if (x % y == 0) { return y; }
|
||||
return gcd(y, x % y);
|
||||
}
|
||||
|
||||
class Fraction {
|
||||
public:
|
||||
long long numerator = 0, denominator = 1;
|
||||
|
||||
void simplify() {
|
||||
if (numerator == 0) { denominator = 1; }
|
||||
long long g = gcd(numerator, denominator);
|
||||
numerator /= g, denominator /= g;
|
||||
}
|
||||
|
||||
Fraction operator+(const Fraction& other) const {
|
||||
Fraction result{
|
||||
numerator * other.denominator + denominator * other.numerator,
|
||||
denominator * other.denominator
|
||||
};
|
||||
result.simplify();
|
||||
return result;
|
||||
}
|
||||
|
||||
Fraction operator+=(const Fraction& other) {
|
||||
return *this = *this + other;
|
||||
}
|
||||
|
||||
Fraction() = default;
|
||||
Fraction(const long long n, const long long d) : numerator(n), denominator(d) { simplify(); }
|
||||
|
||||
Fraction(const string& s) {
|
||||
stringstream ss(s);
|
||||
long long n, d;
|
||||
char slash;
|
||||
if (ss >> n >> slash >> d && slash == '/') {
|
||||
numerator = n, denominator = d;
|
||||
simplify();
|
||||
} else {
|
||||
throw invalid_argument("String is not a fraction");
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] string to_string() const {
|
||||
if (denominator == 1) {
|
||||
return std::to_string(numerator);
|
||||
}
|
||||
return std::to_string(numerator) + '/' + std::to_string(denominator);
|
||||
}
|
||||
};
|
||||
|
||||
int n;
|
||||
string s;
|
||||
Fraction ans;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
for (int _ = 0; _ < n; _++) {
|
||||
// clog << ans.numerator << '/' << ans.denominator << endl;
|
||||
cin >> s;
|
||||
ans += Fraction(s);
|
||||
}
|
||||
|
||||
cout << ans.to_string() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Number {
|
||||
int value;
|
||||
int index;
|
||||
|
||||
bool operator<(const Number& other) const {
|
||||
return value < other.value;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr int MAX_N = 1001;
|
||||
int n;
|
||||
Number numbers[MAX_N];
|
||||
int answers[MAX_N];
|
||||
|
||||
void get_answers() {
|
||||
sort(numbers, numbers + n);
|
||||
int real_idx = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (i == 0 || numbers[i].value != numbers[i - 1].value) { real_idx = i; }
|
||||
answers[numbers[i].index] = real_idx;
|
||||
}
|
||||
}
|
||||
|
||||
void print_answers() {
|
||||
for (int i = 0; i < n; i++) {
|
||||
cout << answers[i] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> numbers[i].value;
|
||||
numbers[i].index = i;
|
||||
}
|
||||
|
||||
get_answers();
|
||||
print_answers();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
def get_count_digits_init(n: int, d: int) -> int:
|
||||
return str(n).count(str(d))
|
||||
|
||||
|
||||
MAX_N = 10001
|
||||
count_digits_init = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for _ in range(MAX_N)]
|
||||
|
||||
if __name__ == '__main__':
|
||||
for i in range(1, MAX_N):
|
||||
for d in range(10):
|
||||
count_digits_init[i][d] = get_count_digits_init(i, d) + count_digits_init[i - 1][d]
|
||||
# with open('dh_20260909_11_count_digits_init.out', 'w') as f:
|
||||
# f.write(str(count_digits_init).replace(" ", "").replace("]", "}").replace("[", "{"))
|
||||
|
||||
n, d = map(int, input().split())
|
||||
print(count_digits_init[n][d])
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
long long exchange_requirement, empty_bottles_amount, filled_bottles_amount, ans;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> exchange_requirement >> filled_bottles_amount;
|
||||
|
||||
while (true) {
|
||||
ans += filled_bottles_amount;
|
||||
empty_bottles_amount += filled_bottles_amount;
|
||||
filled_bottles_amount = empty_bottles_amount / exchange_requirement;
|
||||
empty_bottles_amount %= exchange_requirement;
|
||||
if (filled_bottles_amount == 0) { break; }
|
||||
}
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
constexpr int MAX_N = 151;
|
||||
bool cards_flipped[MAX_N];
|
||||
|
||||
void simulate() {
|
||||
for (int divider=2; divider<MAX_N; divider++) {
|
||||
for (int i=divider; i<MAX_N; i+=divider) {
|
||||
cards_flipped[i] = !cards_flipped[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_ans() {
|
||||
int amount = 0;
|
||||
bool first = true;
|
||||
for (int i = 1; i < MAX_N; i++) {
|
||||
if (!cards_flipped[i]) {
|
||||
if (!first) cout << " ";
|
||||
cout << "N" << i;
|
||||
first = false;
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
cout << endl << amount << endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
simulate();
|
||||
print_ans();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
class Coord {
|
||||
public:
|
||||
int x = 0, y = 0;
|
||||
constexpr Coord(int x, int y) : x(x), y(y) {}
|
||||
|
||||
constexpr Coord operator+(const Coord other) const {
|
||||
return {x + other.x, y + other.y};
|
||||
}
|
||||
|
||||
constexpr Coord& operator+=(const Coord other) {
|
||||
x += other.x, y += other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Coord other) const {
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Coord coord) {
|
||||
return os << "(" << coord.x << ", " << coord.y << ")";
|
||||
}
|
||||
};
|
||||
|
||||
constexpr int MAX_N = 10;
|
||||
int w, h, grid[MAX_N][MAX_N];
|
||||
std::string original_str;
|
||||
|
||||
std::vector<int> get_nums(const char c) {
|
||||
if (c == ' ') { return {0, 0}; }
|
||||
return {(c - 'A' + 1) / 10, (c - 'A' + 1) % 10};
|
||||
}
|
||||
|
||||
Coord next_move(const Coord prev_coord, const Coord prev_facing) {
|
||||
Coord new_coord = prev_coord + prev_facing;
|
||||
if (new_coord.x < 0 || new_coord.x >= h ||
|
||||
new_coord.y < 0 || new_coord.y >= w ||
|
||||
grid[new_coord.x][new_coord.y] != -1) {
|
||||
if (prev_facing == Coord{1, 0}) { return {0, -1}; }
|
||||
if (prev_facing == Coord{0, -1}) { return {-1, 0}; }
|
||||
if (prev_facing == Coord{-1, 0}) { return {0, 1}; }
|
||||
if (prev_facing == Coord{0, 1}) { return {1, 0}; }
|
||||
throw std::invalid_argument("Invalid facing direction");
|
||||
}
|
||||
return prev_facing;
|
||||
}
|
||||
|
||||
std::ostream& print_grid(std::ostream& os) {
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
os << (grid[i][j] == -1 ? 0 : grid[i][j]);
|
||||
}
|
||||
}
|
||||
os << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
void fill_grid(const std::string& s) {
|
||||
memset(grid, -1, sizeof(grid));
|
||||
Coord coord = {0, 0}, facing = {0, 1};
|
||||
for (const char c : s) {
|
||||
for (const int x : get_nums(c)) {
|
||||
grid[coord.x][coord.y] = x;
|
||||
std::clog << "Placing " << x << " at " << coord << std::endl;
|
||||
print_grid(std::clog);
|
||||
coord += facing = next_move(coord, facing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
getline(std::cin, original_str);
|
||||
std::stringstream ss(original_str);
|
||||
ss >> h >> w;
|
||||
getline(std::cin, original_str);
|
||||
fill_grid(original_str);
|
||||
|
||||
print_grid(std::cout);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <iostream>
|
||||
|
||||
class CycledLinkedList {
|
||||
public:
|
||||
struct Node {
|
||||
int val = 0;
|
||||
Node* next = nullptr;
|
||||
Node* prev = nullptr;
|
||||
};
|
||||
|
||||
Node* head = nullptr; // They are POINTERS, not OBJECTS.
|
||||
|
||||
void push_back(int val) {
|
||||
if (head == nullptr) {
|
||||
head = new Node({.val = val});
|
||||
head->next = head;
|
||||
head->prev = head;
|
||||
return;
|
||||
}
|
||||
Node* node = new Node({.val = val});
|
||||
head->prev->next = node;
|
||||
node->prev = head->prev;
|
||||
head->prev = node;
|
||||
node->next = head;
|
||||
}
|
||||
|
||||
void remove(Node* node) {
|
||||
node->prev->next = node->next;
|
||||
node->next->prev = node->prev;
|
||||
if (node == head) {
|
||||
head = node->next;
|
||||
}
|
||||
delete node;
|
||||
}
|
||||
|
||||
void init_cycle(int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const CycledLinkedList& list) {
|
||||
for (Node* node = list.head->next; node != list.head; node = node->next) {
|
||||
os << node->val << "<->";
|
||||
}
|
||||
os << list.head->val << std::endl;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
int n, m, target_order;
|
||||
CycledLinkedList players;
|
||||
|
||||
int target_idx() {
|
||||
for (int i = 0; i < target_order - 1; i++) {
|
||||
for (int j = 0; j < m - 1; j++) {
|
||||
players.head = players.head->next;
|
||||
}
|
||||
players.remove(players.head);
|
||||
}
|
||||
for (int j = 0; j < m - 1; j++) {
|
||||
players.head = players.head->next;
|
||||
}
|
||||
return players.head->val;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin >> n >> m >> target_order;
|
||||
players.init_cycle(n);
|
||||
// std::clog << players << std::endl;
|
||||
std::cout << target_idx() + 1 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
constexpr size_t MAX_N = 201;
|
||||
int n, evaluation_value, original_evaluation_value;
|
||||
bool bits[MAX_N], original_bits[MAX_N], target_bits[MAX_N];
|
||||
|
||||
std::ostream& print_bits(const bool* bits_list = bits, std::ostream& os = std::clog) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
os << (bits_list[i] ? 1 : 0);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
void swap_bits(int i, int j) {
|
||||
if (bits[i] != target_bits[i]) { evaluation_value--; }
|
||||
if (bits[j] != target_bits[j]) { evaluation_value--; }
|
||||
std::swap(bits[i], bits[j]);
|
||||
if (bits[i] != target_bits[i]) { evaluation_value++; }
|
||||
if (bits[j] != target_bits[j]) { evaluation_value++; }
|
||||
}
|
||||
|
||||
int evaluate() {
|
||||
if (evaluation_value == 1) { return 1; }
|
||||
return evaluation_value / 2;
|
||||
}
|
||||
|
||||
bool dfs(int last_swap_pos = 0, int depth = 0, int target_depth = 0) {
|
||||
const int h = evaluate();
|
||||
if (h == 0) { return true; }
|
||||
if (depth + h > target_depth) {
|
||||
return false;
|
||||
}
|
||||
std::clog << "DEPTH=" << depth << "\th=" << h << "\t";
|
||||
print_bits() << "\t";
|
||||
print_bits(target_bits) << std::endl;
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
if (bits[i] == bits[i + 1]) { continue; }
|
||||
if (i == last_swap_pos) { continue; }
|
||||
if (bits[i] == target_bits[i] && bits[i + 1] == target_bits[i + 1]) { continue; }
|
||||
if ((bits[i] == target_bits[i] || bits[i + 1] == target_bits[i + 1]) &&
|
||||
(bits[i + 1] != target_bits[i] && bits[i] != target_bits[i + 1])) { continue; }
|
||||
swap_bits(bits[i], bits[i + 1]);
|
||||
if (dfs(i, depth + 1, target_depth)) { return true; }
|
||||
swap_bits(bits[i], bits[i + 1]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ida_star() {
|
||||
for (int target_depth = evaluate(); target_depth <= 2 * n; target_depth++) {
|
||||
memcpy(bits, original_bits, n);
|
||||
evaluation_value = original_evaluation_value;
|
||||
std::clog << "target_depth:" << target_depth << std::endl;
|
||||
if (dfs(-1, 0, target_depth)) {
|
||||
return target_depth;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool init_evaluate() {
|
||||
int original_sum = 0, target_sum = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
original_sum += original_bits[i];
|
||||
target_sum += target_bits[i];
|
||||
original_evaluation_value += original_bits[i] != target_bits[i];
|
||||
}
|
||||
return original_sum == target_sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin >> n;
|
||||
for (int i = 0; i < n; i++) { std::cin >> original_bits[i]; }
|
||||
for (int i = 0; i < n; i++) { std::cin >> target_bits[i]; }
|
||||
if (!init_evaluate()) {
|
||||
std::cout << -1 << std::endl;
|
||||
return 0;
|
||||
}
|
||||
std::cout << ida_star() << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int afford_year(double salary, double price, int current_year = 1, double current_money = 0) {
|
||||
if ((current_money += salary) >= price) { return current_year; }
|
||||
if (current_year > 100) { return -1; }
|
||||
return afford_year(salary * 1.08, price * 1.10, current_year + 1, current_money);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
double money, price;
|
||||
int ans;
|
||||
cin >> money >> price;
|
||||
|
||||
if ((ans = afford_year(money, price)) == -1) {
|
||||
cout << "Forget it." << endl;
|
||||
} else {
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
double get_price(int spent_money, int distance) {
|
||||
double price = 0;
|
||||
if (distance <= 6) {
|
||||
price = 3;
|
||||
} else {
|
||||
price = 4;
|
||||
}
|
||||
distance -= 12;
|
||||
if (distance > 0 && distance <= 32 - 12) { price += ceil(distance / 10.0); }
|
||||
distance -= 32 - 12;
|
||||
if (distance > 0) { price += ceil(distance / 20.0); }
|
||||
if (spent_money >= 400) { return price; }
|
||||
if (spent_money >= 150) { return price * 0.5; }
|
||||
if (spent_money >= 100) { return price * 0.8; }
|
||||
return price;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int spent_money, distance;
|
||||
cin >> spent_money >> distance;
|
||||
cout << fixed << setprecision(2) << get_price(spent_money, distance) << endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
string token;
|
||||
float coord[2];
|
||||
|
||||
for (int i = 0; getline(cin, token, ','); i++) {
|
||||
coord[i] = stof(token);
|
||||
}
|
||||
|
||||
if (-1 <= coord[0] && coord[0] <= 1 && -1 <= coord[1] && coord[1] <= 1) {
|
||||
cout << "yes" << endl;
|
||||
} else {
|
||||
cout << "no" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> calc_factors( int num) {
|
||||
vector<int> factors;
|
||||
for (const int factor : {3,5,7}) {
|
||||
if (num % factor == 0) {
|
||||
factors.push_back(factor);
|
||||
}
|
||||
}
|
||||
return factors;
|
||||
}
|
||||
|
||||
int num;
|
||||
vector<int> factors;
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> num;
|
||||
factors = calc_factors(num);
|
||||
if (factors.empty()) {
|
||||
cout << "n" << endl;
|
||||
} else {
|
||||
int temp = factors[factors.size() - 1];
|
||||
factors.pop_back();
|
||||
for (const int factor : factors) {
|
||||
cout << factor << " ";
|
||||
}
|
||||
cout << temp << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
constexpr int MAX_X = 15;
|
||||
int n, winner;
|
||||
unsigned int bucket[MAX_X + 1];
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n;
|
||||
for (int _ = 0; _ < n; _++) {
|
||||
int x;
|
||||
cin >> x;
|
||||
bucket[x]++;
|
||||
}
|
||||
winner = 0;
|
||||
for (int x = 1; x <= MAX_X; x++) {
|
||||
if (bucket[x] > bucket[winner]) {
|
||||
winner = x;
|
||||
}
|
||||
}
|
||||
cout << winner << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
|
||||
double get_bike_time(double distance) {
|
||||
return 27 + 23 + distance / 3;
|
||||
}
|
||||
|
||||
double get_walk_time(double distance) {
|
||||
return distance * 5 / 6;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int distance;
|
||||
std::cin >> distance;
|
||||
while (std::cin >> distance) {
|
||||
double diff = get_bike_time(distance) - get_walk_time(distance);
|
||||
if (diff < 1e-8 && diff > -1e-8) {
|
||||
std::cout << "All" << std::endl;
|
||||
} else if (diff < 0) {
|
||||
std::cout << "Bike" << std::endl;
|
||||
} else {
|
||||
std::cout << "Walk" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
|
||||
void print_filled_rectangle(int h, int w, char c) {
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
std::cout << c;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void print_unfilled_rectangle(int h, int w, char c) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
std::cout << c;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
for (int i = 0; i < h - 2; i++) {
|
||||
std::cout << c;
|
||||
for (int j = 0; j < w - 2; j++) {
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << c << std::endl;
|
||||
}
|
||||
for (int i = 0; i < w; i++) {
|
||||
std::cout << c;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
int h, w;
|
||||
char c;
|
||||
bool filled;
|
||||
|
||||
while (std::cin >> h >> w >> c >> filled) {
|
||||
if (filled) {
|
||||
print_filled_rectangle(h, w, c);
|
||||
} else {
|
||||
print_unfilled_rectangle(h, w, c);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
int get_digit(int num, int digit) {
|
||||
num /= static_cast<int>(std::pow(10, digit));
|
||||
// std::clog << num << " is " << digit << "->" << std::endl;
|
||||
return num % 10;
|
||||
}
|
||||
|
||||
bool is_good_num(int num) {
|
||||
return get_digit(num, 0)
|
||||
- (get_digit(num, 3) + get_digit(num, 2) + get_digit(num, 1))
|
||||
> 0;
|
||||
}
|
||||
|
||||
int n, ans;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
std::cin >> n;
|
||||
for (int _ = 0; _ < n; _++) {
|
||||
int num;
|
||||
std::cin >> num;
|
||||
ans += is_good_num(num);
|
||||
}
|
||||
std::cout << ans << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
|
||||
constexpr int MAX_N = 1001;
|
||||
|
||||
int n;
|
||||
bool lamps[MAX_N]; // 第 0 盏放弃
|
||||
|
||||
void simulate() {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 0; j <= n; j += i) {
|
||||
lamps[j] = !lamps[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
std::cin >> n;
|
||||
simulate();
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (!lamps[i]) {
|
||||
std::cout << i << " ";
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user