some programs!!!
This commit is contained in:
1 parent
71f1022dea
commit
ca6daa582c
43 files changed
+1452
-381
No files matched your search
Generated
+418
-331
File diff suppressed because it is too large.
Load diff
@@ -7,6 +7,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCES "*.cpp" "*.c")
|
file(GLOB_RECURSE SOURCES "*.cpp" "*.c")
|
||||||
|
|
||||||
foreach (source ${SOURCES})
|
foreach (source ${SOURCES})
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define _NOT_USED \
|
||||||
|
'''
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int a, b;
|
||||||
|
scanf("%d%d", &a, &b);
|
||||||
|
printf("%d", a + b);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define _NOT_USED \
|
||||||
|
'''
|
||||||
|
|
||||||
|
#define _NOT_USED /*
|
||||||
|
|
||||||
|
a, b = map(int, input().split())
|
||||||
|
print(a + b)
|
||||||
|
|
||||||
|
#*/
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
long long T; //注意变量都要初始化 ,T为数组个数
|
|
||||||
scanf("%lld", &T); //数组个数,决定过程要执行多少次
|
|
||||||
for (int i = 0; i < T; i++) {
|
|
||||||
long long n, m, bianhao, yushu, max = -1, index; //注意变量都要初始化,n为包裹个数,m为箱子个数,result是余数,max是装的最多
|
|
||||||
//以上变量必须定义在循环里,因为一组过后所有数据要重新开始!要不然max,index值未清除!
|
|
||||||
scanf("%lld%lld", &n, &m); //键入包裹的个数和箱子的个数
|
|
||||||
long long Amount[m], number[n]; //Amount是定义对应的箱子里装几个 ,number是用数组记录包裹的“编号”
|
|
||||||
//禁止写错数组个数!
|
|
||||||
for (int j = 0; j < m; j++) //初始化箱子数组 ,注意数组是m个
|
|
||||||
{
|
|
||||||
Amount[j] = 0;
|
|
||||||
}
|
|
||||||
for (int k = 0; k < n; k++) //把包裹赋值,记录到number里 注意数组是n个
|
|
||||||
{
|
|
||||||
scanf("%lld", &bianhao);
|
|
||||||
number[k] = bianhao;
|
|
||||||
}
|
|
||||||
for (int s = 0; s < n; s++) //进行mol m运算,余数计入number里
|
|
||||||
{
|
|
||||||
yushu = number[s] % m;
|
|
||||||
Amount[yushu] = Amount[yushu] + 1;
|
|
||||||
}
|
|
||||||
for (int t = 0; t < m; t++) //此循环计算哪个箱子装的最多
|
|
||||||
{
|
|
||||||
//max=-1;错误 在循环里定义会导致max每走一个t都会被重置!
|
|
||||||
if (max < Amount[t]) {
|
|
||||||
max = Amount[t];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int u = 0; u < m; u++) //此循环寻找下标
|
|
||||||
{
|
|
||||||
if (Amount[u] == max) {
|
|
||||||
index = u;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int v = 0; v < m; v++) //此循环输出amount数组里各个元素的大小
|
|
||||||
{
|
|
||||||
printf("%lld ", Amount[v]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
printf("%lld %lld", index, max);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
constexpr float ALLOWED_DIFF = 1e-6;
|
||||||
|
|
||||||
|
std::tuple<int, double> sqrt_custom(double x) {
|
||||||
|
double est_prev = -1, est_curr = x;
|
||||||
|
int rounds = 0;
|
||||||
|
while (abs(est_curr - est_prev) > ALLOWED_DIFF) {
|
||||||
|
est_prev = est_curr;
|
||||||
|
// est_curr = 0.5 * (est_prev + x / est_prev);
|
||||||
|
est_curr = x / (2 * est_curr) + 0.5 * est_curr;
|
||||||
|
rounds++;
|
||||||
|
}
|
||||||
|
return std::make_tuple(rounds, est_curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
int x;
|
||||||
|
while (std::cin >> x) {
|
||||||
|
auto [rounds, ans] = sqrt_custom(x);
|
||||||
|
std::cout << rounds << " " << std::fixed << std::setprecision(2) << ans << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,29 @@
|
|||||||
|
#include <cmath>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
constexpr float ALLOWED_DIFF = 1e-6;
|
||||||
|
|
||||||
|
std::tuple<int, double> sqrt_custom(double x) {
|
||||||
|
double est_prev = -1, est_curr = x;
|
||||||
|
int rounds = 0;
|
||||||
|
while (std::abs(est_curr - est_prev) > ALLOWED_DIFF) {
|
||||||
|
est_prev = est_curr;
|
||||||
|
est_curr = 0.5 * (est_prev + x / est_prev);
|
||||||
|
// est_curr = x / (2 * est_prev) + 0.5 * est_prev;
|
||||||
|
rounds++;
|
||||||
|
}
|
||||||
|
return std::make_tuple(rounds, est_curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
int x;
|
||||||
|
while (std::cin >> x) {
|
||||||
|
auto [rounds, ans] = sqrt_custom(x);
|
||||||
|
std::cout << rounds << " " << std::fixed << std::setprecision(2) << ans << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
short get_digit(int num, int digit) {
|
||||||
|
return num / static_cast<int>(pow(10, digit)) % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::tuple<int, int, int>> answers;
|
||||||
|
bool digits_bucket[10];
|
||||||
|
int nums[3];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
for (nums[0] = 123; nums[0] <= 333; nums[0]++) {
|
||||||
|
memset(digits_bucket, false, sizeof(digits_bucket));
|
||||||
|
nums[1] = 2 * nums[0], nums[2] = 3 * nums[0];
|
||||||
|
bool success_flag = true;
|
||||||
|
for (int num : nums) {
|
||||||
|
for (int digit = 0; digit < 3; digit++) {
|
||||||
|
int x = get_digit(num, digit);
|
||||||
|
if (digits_bucket[x] || x == 0) {
|
||||||
|
success_flag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
digits_bucket[x] = true;
|
||||||
|
}
|
||||||
|
if (!success_flag) { break; }
|
||||||
|
}
|
||||||
|
if (success_flag) {
|
||||||
|
answers.emplace_back(nums[0], nums[1], nums[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto [a,b,c] : answers) {
|
||||||
|
std::cout << a << " " << b << " " << c << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int ans;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
for (int _ = 0; _ < n; _++) {
|
||||||
|
int x;
|
||||||
|
std::cin >> x;
|
||||||
|
ans ^= x;
|
||||||
|
}
|
||||||
|
std::cout << ans << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
int chicken_count, coroutines;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin >> chicken_count >> coroutines;
|
||||||
|
if (chicken_count == 1) {
|
||||||
|
std::cout << 2 << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::cout << static_cast<int>(ceil(1.0l * chicken_count * 2 / coroutines)) << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
constexpr int MAX_N = 1e5 + 1;
|
||||||
|
|
||||||
|
int calc_factors_sum(int x) {
|
||||||
|
int sum = 0, i = 1;
|
||||||
|
for (i = 1; i * i < x; i++) {
|
||||||
|
if (x % i == 0) { sum += i + x / i; }
|
||||||
|
}
|
||||||
|
if (i * i == x) { sum += i; }
|
||||||
|
return sum - x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
for (int a = 220; a <= n; a++) {
|
||||||
|
int b = calc_factors_sum(a);
|
||||||
|
if (b > a && b <= n && calc_factors_sum(b) == a) {
|
||||||
|
std::cout << a << " " << b << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
#include <array>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include <chrono>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
constexpr int MAX_N = 1e5 + 1;
|
||||||
|
|
||||||
|
std::vector<int> primes;
|
||||||
|
std::array<bool, MAX_N> not_prime;
|
||||||
|
|
||||||
|
std::multiset<std::pair<long long, int>, std::greater<>> calc_times, calc_times_old;
|
||||||
|
|
||||||
|
void init_primes() {
|
||||||
|
primes.reserve(MAX_N / 10);
|
||||||
|
primes.push_back(2);
|
||||||
|
|
||||||
|
for (int i = 3; i < MAX_N; i++) {
|
||||||
|
if (!not_prime[i]) {
|
||||||
|
primes.push_back(i);
|
||||||
|
for (int x = i + i; x < MAX_N; x += i) {
|
||||||
|
not_prime[x] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// int shit = 0;
|
||||||
|
// for (int i = 0; i < 10000000; i++) {
|
||||||
|
// shit++;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
long long calc_factors_sum(int x) {
|
||||||
|
// std::vector<int> prime_exponents(primes.size());
|
||||||
|
std::array<int, MAX_N / 10> prime_exponents{};
|
||||||
|
int prime_idx = 0, old_x = x;
|
||||||
|
while (x > 1) {
|
||||||
|
if (x % primes[prime_idx] == 0) {
|
||||||
|
x /= primes[prime_idx], prime_exponents[prime_idx]++;
|
||||||
|
} else {
|
||||||
|
prime_idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long long sum = 1;
|
||||||
|
for (int i = 0; i <= prime_idx; i++) {
|
||||||
|
if (!prime_exponents[i]) { continue; }
|
||||||
|
if (prime_exponents[i] == 1) {
|
||||||
|
sum *= primes[i] + 1;
|
||||||
|
} else {
|
||||||
|
sum *= (static_cast<long long>(std::pow(primes[i], prime_exponents[i] + 1)) - 1)
|
||||||
|
/ (primes[i] - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// std::clog << sum << std::endl;
|
||||||
|
return sum - old_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long long calc_factors_sum_old(int x) {
|
||||||
|
long long sum = 0;
|
||||||
|
int i = 1;
|
||||||
|
for (i = 1; i * i < x; i++) {
|
||||||
|
if (x % i == 0) { sum += i + x / i; }
|
||||||
|
}
|
||||||
|
if (i * i == x) { sum += i; }
|
||||||
|
return sum - x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Func, typename... Args>
|
||||||
|
auto time_function(const std::string& name, Func&& func, Args&&... args) {
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
// 完美转发参数并调用函数
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
auto result = std::forward<Func>(func)(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||||
|
|
||||||
|
// std::clog << "[" << name << "] 耗时: "
|
||||||
|
// << duration.count() << " μs " << std::endl;
|
||||||
|
|
||||||
|
// return result; // 返回函数的返回值(如果有)
|
||||||
|
return duration.count() / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
// auto s1 = std::chrono::high_resolution_clock::now();
|
||||||
|
// init_primes();
|
||||||
|
// auto e1 = std::chrono::high_resolution_clock::now();
|
||||||
|
// auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(e1 - s1);
|
||||||
|
//
|
||||||
|
// std::clog << duration.count() << std::endl;
|
||||||
|
|
||||||
|
init_primes();
|
||||||
|
|
||||||
|
std::cout << "OLD" << std::endl;
|
||||||
|
for (int x = 2; x < MAX_N; x++) {
|
||||||
|
calc_times_old.insert({time_function("", calc_factors_sum_old, x), x});
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (auto it = calc_times_old.begin(); it != calc_times_old.end() && count < 10; ++it, ++count) {
|
||||||
|
std::cout << "OLD " << it->second << "->" << it->first << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "NEW" << std::endl;
|
||||||
|
for (int x = 2; x < MAX_N; x++) {
|
||||||
|
calc_times.insert({time_function("", calc_factors_sum, x), x});
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (auto it = calc_times.begin(); it != calc_times.end() && count < 10; ++it, ++count) {
|
||||||
|
std::cout << it->second << "->" << it->first << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// int n;
|
||||||
|
// std::cin >> n;
|
||||||
|
// for (int a = 220; a <= n; a++) {
|
||||||
|
// long long b = calc_factors_sum(a);
|
||||||
|
// if (b > MAX_N) { continue; }
|
||||||
|
// if (b > a && b <= n && calc_factors_sum(static_cast<int>(b)) == a) {
|
||||||
|
// std::cout << a << " " << b << std::endl;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#include <array>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
constexpr int MAX_N = 1e5 + 1;
|
||||||
|
|
||||||
|
std::vector<int> primes;
|
||||||
|
std::array<bool, MAX_N> not_prime;
|
||||||
|
|
||||||
|
void init_primes() {
|
||||||
|
primes.reserve(MAX_N / 10);
|
||||||
|
primes.push_back(2);
|
||||||
|
|
||||||
|
for (int i = 3; i < MAX_N; i++) {
|
||||||
|
if (!not_prime[i]) {
|
||||||
|
primes.push_back(i);
|
||||||
|
for (int x = i + i; x < MAX_N; x += i) {
|
||||||
|
not_prime[x] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long long calc_factors_sum(int x) {
|
||||||
|
std::vector<int> prime_exponents(primes.size());
|
||||||
|
int prime_idx = 0, old_x = x;
|
||||||
|
while (x > 1) {
|
||||||
|
if (x % primes[prime_idx] == 0) {
|
||||||
|
x /= primes[prime_idx], prime_exponents[prime_idx]++;
|
||||||
|
} else {
|
||||||
|
prime_idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long long sum = 1;
|
||||||
|
for (int i = 0; i <= prime_idx; i++) {
|
||||||
|
if (!prime_exponents[i]) { continue; }
|
||||||
|
if (prime_exponents[i] == 1) {
|
||||||
|
sum *= primes[i] + 1;
|
||||||
|
} else {
|
||||||
|
sum *= (static_cast<long long>(std::pow(primes[i], prime_exponents[i] + 1)) - 1)
|
||||||
|
/ (primes[i] - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// std::clog << sum << std::endl;
|
||||||
|
return sum - old_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
init_primes();
|
||||||
|
|
||||||
|
int n;
|
||||||
|
std::cin >> n;
|
||||||
|
for (int a = 220; a <= n; a++) {
|
||||||
|
long long b = calc_factors_sum(a);
|
||||||
|
if (b > MAX_N) { continue; }
|
||||||
|
if (b > a && b <= n && calc_factors_sum(static_cast<int>(b)) == a) {
|
||||||
|
std::cout << a << " " << b << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#include <array>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Vector2 {
|
||||||
|
public:
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
constexpr int& operator[](const std::size_t idx) {
|
||||||
|
switch (idx) {
|
||||||
|
case 0: return x;
|
||||||
|
case 1: return y;
|
||||||
|
default: throw std::invalid_argument("Index should be 0 or 1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector2 operator+(const Vector2 other) const {
|
||||||
|
return Vector2{x + other.x, y + other.y};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector2 operator-() const {
|
||||||
|
return Vector2{-x, -y};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vector2 operator-(const Vector2 other) const {
|
||||||
|
return *this + -other;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr static int cross(const Vector2 a, const Vector2 b) {
|
||||||
|
return a.x * b.y - a.y * b.x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_convex(std::vector<Vector2> polygon) {
|
||||||
|
for (int i = 0; i < polygon.size() - 1; i++) {
|
||||||
|
// if (Vector2::cross(polygon[i], polygon[i + 1]) * sign <= 0) { return false; }
|
||||||
|
// Vector2 side1 = polygon[i + 1] - polygon[i];
|
||||||
|
int sign = 0;
|
||||||
|
for (int j = 0; j < polygon.size(); j++) {
|
||||||
|
if (i == j || i + 1 == j) { continue; }
|
||||||
|
if (sign == 0) {
|
||||||
|
sign = Vector2::cross(polygon[i] - polygon[i + 1], polygon[j] - polygon[i + 1]);
|
||||||
|
if (sign == 0) { return false; }
|
||||||
|
sign = sign > 0 ? 1 : -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (Vector2::cross(polygon[i] - polygon[i + 1], polygon[j] - polygon[i + 1]) * sign <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::vector<Vector2> coords(4);
|
||||||
|
|
||||||
|
while (std::cin >> coords[0].x >> coords[0].y) {
|
||||||
|
for (int i = 1; i <= 3; ++i) { std::cin >> coords[i].x >> coords[i].y; }
|
||||||
|
std::cout << (is_convex(coords) ? "yes" : "no") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
constexpr int MAX_N = 10001, MAX_D = 50;
|
||||||
|
|
||||||
|
int get_digits_sum(int x) {
|
||||||
|
int sum = 0;
|
||||||
|
while (x) {
|
||||||
|
sum += x % 10;
|
||||||
|
x /= 10;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int m, n, k;
|
||||||
|
std::vector<int> bucket[MAX_D];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
char temp_buffer;
|
||||||
|
std::cin >> m >> temp_buffer >> n >> temp_buffer >> k;
|
||||||
|
|
||||||
|
for (int x = m + 1; x < n; x++) {
|
||||||
|
int digits_sum = get_digits_sum(x);
|
||||||
|
if (digits_sum % k != 0) { continue; }
|
||||||
|
bucket[digits_sum].push_back(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& nums : bucket) {
|
||||||
|
if (nums.empty()) { continue; }
|
||||||
|
bool first = true;
|
||||||
|
for (int num : nums) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
std::cout << num;
|
||||||
|
} else {
|
||||||
|
std::cout << ',' << num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
constexpr std::size_t MAX_N = 501;
|
||||||
|
constexpr int INF = 0x3f3f3f3f;
|
||||||
|
|
||||||
|
using ChangedCoins = std::tuple<int, int, int, int>;
|
||||||
|
|
||||||
|
constexpr int calc_coin_amount(const ChangedCoins& coins) {
|
||||||
|
return std::get<0>(coins) + std::get<1>(coins) + std::get<2>(coins) + std::get<3>(coins);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangedCoins dp[MAX_N];
|
||||||
|
|
||||||
|
|
||||||
|
void init_dp() {
|
||||||
|
for (int i = 1; i < MAX_N; i++) {
|
||||||
|
dp[i] = dp[i - 1], std::get<3>(dp[i])++;
|
||||||
|
if (i - 25 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 25])) {
|
||||||
|
dp[i] = dp[i - 25], std::get<0>(dp[i])++;
|
||||||
|
}
|
||||||
|
if (i - 10 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 10])) {
|
||||||
|
dp[i] = dp[i - 10], std::get<1>(dp[i])++;
|
||||||
|
}
|
||||||
|
if (i - 5 >= 0 && calc_coin_amount(dp[i]) > calc_coin_amount(dp[i - 5])) {
|
||||||
|
dp[i] = dp[i - 5], std::get<2>(dp[i])++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
init_dp();
|
||||||
|
|
||||||
|
int cents;
|
||||||
|
std::cin >> cents;
|
||||||
|
for (int i = 1; std::cin >> cents; i++) {
|
||||||
|
std::cout
|
||||||
|
<< i << ' '
|
||||||
|
<< std::get<0>(dp[cents]) << " QUARTER(S),"
|
||||||
|
<< std::get<1>(dp[cents]) << " DIME(S),"
|
||||||
|
<< std::get<2>(dp[cents]) << " NICKEL(S),"
|
||||||
|
<< std::get<3>(dp[cents]) << " PENNY(S)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using IntWithBase = std::string;
|
||||||
|
|
||||||
|
IntWithBase dec_to_base(int x, unsigned short base) {
|
||||||
|
IntWithBase result;
|
||||||
|
while (x) {
|
||||||
|
result += static_cast<char>(x % base + '0');
|
||||||
|
x /= base;
|
||||||
|
}
|
||||||
|
std::reverse(result.begin(), result.end());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
int op;
|
||||||
|
std::cin >> op;
|
||||||
|
|
||||||
|
for (int x = 0; ; x++) {
|
||||||
|
IntWithBase x7 = dec_to_base(x, 7), x9 = dec_to_base(x, 9);
|
||||||
|
if (x7.length() != 3 || x9.length() != 3) { continue; }
|
||||||
|
if (x7[0] == x9[2] && x7[1] == x9[1] && x7[2] == x9[0]) {
|
||||||
|
if (op == 1) {
|
||||||
|
std::cout << x << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << (op == 2 ? x7 : x9) << std::endl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
constexpr int DEFAULT_JUMPS = 60, STOP_PUNISHMENT = 3;
|
||||||
|
|
||||||
|
int get_actual_jumps(std::vector<int> counted_jumps) {
|
||||||
|
counted_jumps.push_back(DEFAULT_JUMPS);
|
||||||
|
for (int i = 0; i < counted_jumps.size(); i++) {
|
||||||
|
if (counted_jumps[i] + 3 * i >= DEFAULT_JUMPS - STOP_PUNISHMENT) {
|
||||||
|
return std::min(counted_jumps[i] + STOP_PUNISHMENT * i, DEFAULT_JUMPS)
|
||||||
|
- STOP_PUNISHMENT * i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw std::logic_error("Wrong algorithm");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
int n, m;
|
||||||
|
std::cin >> n;
|
||||||
|
for (int _ = 0; _ < n; _++) {
|
||||||
|
std::cin >> m;
|
||||||
|
std::vector<int> counted_jumps(m);
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
std::cin >> counted_jumps[i];
|
||||||
|
}
|
||||||
|
std::cout << get_actual_jumps(counted_jumps) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,52 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
constexpr size_t MAX_HEIGHT = 4e4 + 1, MAX_EGGS = 30, INF = 0x3f3f3f3f;
|
||||||
|
int eggs_amount, height;
|
||||||
|
|
||||||
|
int dp[MAX_HEIGHT][MAX_EGGS];
|
||||||
|
bool ping_pong;
|
||||||
|
|
||||||
|
void print_dp(std::ostream& os = std::clog, int h = MAX_HEIGHT - 1) {
|
||||||
|
for (int i = 0; i <= h; i++) {
|
||||||
|
for (int j = 0; j < MAX_EGGS; j++) {
|
||||||
|
os << dp[i][j] << " ";
|
||||||
|
}
|
||||||
|
os << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_dp() {
|
||||||
|
for (int i = 0; i < MAX_HEIGHT; i++) {
|
||||||
|
dp[i][1] = i;
|
||||||
|
}
|
||||||
|
for (int h = 1; h < MAX_HEIGHT; h++) {
|
||||||
|
for (int eggs = 2; eggs < MAX_EGGS; eggs++) {
|
||||||
|
int min_value = +INF;
|
||||||
|
for (int i = 1; i <= h; i++) {
|
||||||
|
min_value = std::min(
|
||||||
|
min_value, std::max(dp[i - 1][eggs - 1], dp[h - i][eggs]));
|
||||||
|
}
|
||||||
|
dp[h][eggs] = min_value + 1;
|
||||||
|
if (eggs >= dp[h][eggs]) {
|
||||||
|
for (int i = eggs; i < MAX_EGGS; i++) { dp[h][i] = dp[h][eggs]; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_dp(std::clog, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
init_dp();
|
||||||
|
while (std::cin >> height >> eggs_amount && height) {
|
||||||
|
// if (height >= MAX_HEIGHT || eggs_amount >= MAX_EGGS) {
|
||||||
|
// throw std::overflow_error("Oh no!");
|
||||||
|
// }
|
||||||
|
// if (eggs_amount >= MAX_EGGS) { eggs_amount = MAX_EGGS - 1; }
|
||||||
|
std::cout << dp[height][eggs_amount] << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
constexpr int MAX_N = 1e6 + 1;
|
||||||
|
int n, ans = 0;
|
||||||
|
int values[MAX_N], sums[MAX_N], min_sums[2][MAX_N];
|
||||||
|
|
||||||
|
void init_sums() {
|
||||||
|
sums[0] = values[0];
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
sums[i] = sums[i - 1] + values[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_min_sums() {
|
||||||
|
min_sums[0][0] = sums[0];
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
min_sums[0][i] = std::min(min_sums[0][i - 1], sums[i]);
|
||||||
|
}
|
||||||
|
min_sums[1][n - 1] = sums[n - 1];
|
||||||
|
for (int i = n - 2; i >= 0; i--) {
|
||||||
|
min_sums[1][i] = std::min(min_sums[1][i + 1], sums[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin >> n;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
std::cin >> values[i];
|
||||||
|
}
|
||||||
|
init_sums();
|
||||||
|
init_min_sums();
|
||||||
|
|
||||||
|
for (int i = 0; i < n - 1; i++) {
|
||||||
|
int delta1 = sums[i];
|
||||||
|
int delta2 = sums[n - 1] - sums[i];
|
||||||
|
if (min_sums[0][i] + delta2 >= 0 && min_sums[1][i + 1] - delta1 >= 0) {
|
||||||
|
std::clog << i << std::endl;
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool flag = false;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (sums[i] < 0) {
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
std::clog << n - 1 << std::endl;
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << ans << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
constexpr int MAX_G = 301;
|
||||||
|
|
||||||
|
template <typename NodeT>
|
||||||
|
class LinkedList {
|
||||||
|
public:
|
||||||
|
NodeT* head = new NodeT();
|
||||||
|
NodeT* tail = head;
|
||||||
|
|
||||||
|
NodeT* push_front(int val) {
|
||||||
|
auto* node = new NodeT{.val = val};
|
||||||
|
push_front(node);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_front(NodeT* node) {
|
||||||
|
tail->next = node;
|
||||||
|
tail = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_back(NodeT* node) {
|
||||||
|
node->next = head->next;
|
||||||
|
head->next = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pop_back() {
|
||||||
|
NodeT* prev_node = head->next;
|
||||||
|
head->next = prev_node->next;
|
||||||
|
if (tail == prev_node) { tail = head; }
|
||||||
|
int val = prev_node->val;
|
||||||
|
delete prev_node;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeT* back() {
|
||||||
|
return head->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() {
|
||||||
|
return head == tail;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
int val = -1;
|
||||||
|
Node* next = nullptr;
|
||||||
|
// Node* prev = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AdvancedNode : Node {
|
||||||
|
using Node::Node;
|
||||||
|
int group{};
|
||||||
|
AdvancedNode* next = nullptr;
|
||||||
|
LinkedList<Node> children;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AdvancedLinkedList : public LinkedList<AdvancedNode> {
|
||||||
|
public:
|
||||||
|
// Node* head = new Node();
|
||||||
|
AdvancedNode* father_nodes[MAX_G] = {};
|
||||||
|
|
||||||
|
AdvancedNode* push_front(int val, int grp) {
|
||||||
|
auto* node = new AdvancedNode();
|
||||||
|
node->val = val, node->group = grp;
|
||||||
|
if (father_nodes[grp] == nullptr) {
|
||||||
|
father_nodes[grp] = node;
|
||||||
|
LinkedList::push_front(node);
|
||||||
|
} else {
|
||||||
|
father_nodes[grp]->children.push_front(node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int pop_back() {
|
||||||
|
if (back()->children.empty()) {
|
||||||
|
father_nodes[back()->group] = nullptr;
|
||||||
|
return LinkedList::pop_back();
|
||||||
|
}
|
||||||
|
int current_val = back()->val;
|
||||||
|
back()->val = back()->children.pop_back();
|
||||||
|
return current_val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
int n, groups_amount;
|
||||||
|
std::vector<int> element_groups;
|
||||||
|
AdvancedLinkedList list;
|
||||||
|
|
||||||
|
std::cin >> n >> groups_amount;
|
||||||
|
element_groups.resize(n);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
std::cin >> element_groups[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cin >> n;
|
||||||
|
std::string op;
|
||||||
|
int elem_id;
|
||||||
|
for (int _ = 0; _ < n; _++) {
|
||||||
|
std::cin >> op;
|
||||||
|
if (op == "push") {
|
||||||
|
std::cin >> elem_id;
|
||||||
|
list.push_front(elem_id, element_groups[elem_id]);
|
||||||
|
} else {
|
||||||
|
std::cout << list.pop_back() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
constexpr int INF = 0x3f3f3f3f;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class QueueWithMinMax : public std::queue<T> {
|
||||||
|
protected:
|
||||||
|
std::deque<T> min_queue;
|
||||||
|
std::deque<T> max_queue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using std::queue<T>::queue;
|
||||||
|
|
||||||
|
void push(T x) {
|
||||||
|
while (!min_queue.empty() && min_queue.back() > x) {
|
||||||
|
min_queue.pop_back();
|
||||||
|
}
|
||||||
|
min_queue.push_back(x);
|
||||||
|
while (!max_queue.empty() && max_queue.back() < x) {
|
||||||
|
max_queue.pop_back();
|
||||||
|
}
|
||||||
|
max_queue.push_back(x);
|
||||||
|
std::queue<T>::push(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop() {
|
||||||
|
if (!min_queue.empty() && min_queue.front() == std::queue<T>::front()) {
|
||||||
|
min_queue.pop_front();
|
||||||
|
}
|
||||||
|
if (!max_queue.empty() && max_queue.front() == std::queue<T>::front()) {
|
||||||
|
max_queue.pop_front();
|
||||||
|
}
|
||||||
|
std::queue<T>::pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
T get_max() {
|
||||||
|
return max_queue.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
T get_min() {
|
||||||
|
return min_queue.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto get_difference() -> decltype(get_max() - get_min()) {
|
||||||
|
if (std::queue<T>::empty()) { return -1; }
|
||||||
|
return get_max() - get_min();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using Range = std::pair<int, int>;
|
||||||
|
using Coord = std::pair<int, int>;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
int n, target_diff;
|
||||||
|
std::vector<Coord> coords;
|
||||||
|
std::vector<int> positions;
|
||||||
|
std::map<int, Range> moments;
|
||||||
|
// std::vector<Range> moments;
|
||||||
|
|
||||||
|
std::cin >> n >> target_diff;
|
||||||
|
coords.resize(n);
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
// std::cin >> positions[i] >> temp;
|
||||||
|
std::cin >> coords[i].first >> coords[i].second;
|
||||||
|
}
|
||||||
|
std::sort(coords.begin(), coords.end());
|
||||||
|
|
||||||
|
int ans = +INF, p1 = 0, p2 = 0;
|
||||||
|
QueueWithMinMax<int> queue;
|
||||||
|
queue.push(coords[0].second);
|
||||||
|
while (p2 < n) {
|
||||||
|
if (queue.get_difference() < target_diff) {
|
||||||
|
p2++;
|
||||||
|
if (p2 < n) { queue.push(coords[p2].second); }
|
||||||
|
} else {
|
||||||
|
if (coords[p1].first == coords[p2].first) {
|
||||||
|
ans = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ans = std::min(ans, coords[p2].first - coords[p1].first);
|
||||||
|
p1++;
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ans == +INF) { ans = -1; }
|
||||||
|
std::cout << ans << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
constexpr int INF = 0x3f3f3f3f;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class QueueWithMinMax : public std::queue<T> {
|
||||||
|
protected:
|
||||||
|
std::deque<T> min_queue;
|
||||||
|
std::deque<T> max_queue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using std::queue<T>::queue;
|
||||||
|
|
||||||
|
void push(T x) {
|
||||||
|
while (!min_queue.empty() && min_queue.back() > x) {
|
||||||
|
min_queue.pop_back();
|
||||||
|
}
|
||||||
|
min_queue.push_back(x);
|
||||||
|
while (!max_queue.empty() && max_queue.back() < x) {
|
||||||
|
max_queue.pop_back();
|
||||||
|
}
|
||||||
|
max_queue.push_back(x);
|
||||||
|
std::queue<T>::push(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop() {
|
||||||
|
if (!min_queue.empty() && min_queue.front() == std::queue<T>::front()) {
|
||||||
|
min_queue.pop_front();
|
||||||
|
}
|
||||||
|
if (!max_queue.empty() && max_queue.front() == std::queue<T>::front()) {
|
||||||
|
max_queue.pop_front();
|
||||||
|
}
|
||||||
|
std::queue<T>::pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
T get_max() {
|
||||||
|
return max_queue.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
T get_min() {
|
||||||
|
return min_queue.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto get_difference() -> decltype(get_max() - get_min()) {
|
||||||
|
if (std::queue<T>::empty()) { return -1; }
|
||||||
|
return get_max() - get_min();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using Range = std::pair<int, int>;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
int n, target_diff;
|
||||||
|
std::vector<int> positions;
|
||||||
|
std::vector<Range> moments;
|
||||||
|
|
||||||
|
std::cin >> n >> target_diff;
|
||||||
|
positions.resize(n), moments.assign(n, Range(INF, -INF));
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
int temp;
|
||||||
|
std::cin >> positions[i] >> temp;
|
||||||
|
// moments[i].first = std::min(moments[i].first, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ans = +INF, p1 = 0, p2 = 0;
|
||||||
|
QueueWithMinMax<int> queue;
|
||||||
|
queue.push(moments[0]);
|
||||||
|
while (p2 < n) {
|
||||||
|
if (queue.get_difference() < target_diff) {
|
||||||
|
p2++;
|
||||||
|
if (p2 < n) { queue.push(moments[p2]); }
|
||||||
|
} else {
|
||||||
|
ans = std::min(ans, p2 - p1 + 1);
|
||||||
|
p1++;
|
||||||
|
queue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << ans << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user