数算!

This commit is contained in:
rogerwang2008 committed 2026-10-16 10:21:53 +08:00
1 parent ca6daa582c
commit e0c09e0c7b
22 files changed
+1344 -105

No files matched your search

+35 -16
View File
@@ -1,29 +1,48 @@
#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
constexpr int MAX_N = 1001, MAX_T = 1001;
constexpr float ALLOWED_DIFF = 1e-6;
struct Attendee {
int enter_time = 0, exit_time = 0;
};
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++;
int get_max_attendees_amount(std::vector<Attendee> attendees_schedule) {
std::array<int, MAX_T> bucket{};
for (const auto [enter_time, exit_time] : attendees_schedule) {
for (int t = enter_time; t < exit_time; t++) {
bucket[t]++;
}
}
return std::make_tuple(rounds, est_curr);
return *std::max_element(bucket.begin(), bucket.end());
}
int main() {
std::ios::sync_with_stdio(false);
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::vector<Attendee> attendees;
char temp_comma;
int x;
while (std::cin >> x) {
auto [rounds, ans] = sqrt_custom(x);
std::cout << rounds << " " << std::fixed << std::setprecision(2) << ans << std::endl;
while (true) {
std::cin >> x >> temp_comma;
attendees.push_back({x, -1});
if (temp_comma != ',') {
std::cin.unget();
break;
}
}
for (int i = 0; i < attendees.size() - 1; i++) {
std::cin >> attendees[i].exit_time >> temp_comma;
}
std::cin >> attendees[attendees.size() - 1].exit_time;
std::cout << attendees.size() << ' ' << get_max_attendees_amount(attendees) << std::endl;
return 0;
}