Educational Codeforces Round 156 (Rated for Div. 2) - B+C

B. Fear of the Dark

其实刚开始我想到了需要考虑o点和p点同时包含在a圆或者b圆中的情况;也考虑到了相切的情况

但是后来看题解后发现,在相切的时候,还需要满足o点和p点能够被包含在a圆或者b圆中

cpp 复制代码
#include <math.h>
#include <stdio.h>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
#define de(x) cout << x << " ";
// int n, m, ans;
double px, py, ax, ay, bx, by;
double dis(double x1, double y1, double x2, double y2) {
    return sqrt(1.0 * (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
void solve() {
    cin >> px >> py >> ax >> ay >> bx >> by;
    double ao = dis(0, 0, ax, ay);
    double bo = dis(0, 0, bx, by);
    double ap = dis(px, py, ax, ay);
    double bp = dis(px, py, bx, by);
    double ab = dis(ax, ay, bx, by);
    double ans = 1e9;
    ans = min(ans, max(ao, ap));  // 表示o点和p点在a圆中
    ans = min(ans, max(bo, bp));  // 表示o点和p点在b圆中
    // 表示o点和p点分别在a圆或者b圆中,此时还需要满足相切的条件
    ans = min(ans, max(ab / 2, max(ap, bo)));
    ans = min(ans, max(ab / 2, max(ao, bp)));
    printf("%.10lf\n", ans);
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

C. Decreasing String

看了官方题解才写出来,很巧妙

思路见代码注释

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 2e4 + 9, mod = 1e9 + 7;
// int n, m;
string s;
ll pos;
ll len;
stack<char> q;
void solve() {
    cin >> s >> pos;
    pos--;  // 注意下标是从0开始的
    len = s.size();
    while (!q.empty())
        q.pop();
    bool ok = (pos < len);
    s += '$';  // 很小的ascll码
    for (auto c : s) {
        while (!ok && !q.empty() && q.top() > c) {
            pos -= len;  // 核心,使用线性的复杂度
            // 我们只需要动一个就已经处理了当前长度len下的字符串
            // 而且前面已经在栈中的我们不需要动,因为下一个len-1长度下
            // 需要在栈中已有元素的基础上进行
            len--;
            q.pop();
            if (pos < len)
                ok = true;  // 如果
        }
        q.push(c);
    }
    string tmp = "";
    while (!q.empty())
        tmp += q.top(), q.pop();

    reverse(tmp.begin(), tmp.end());  // 注意这里需要翻转
    // 因为我们得到的字符串是从后往前的

    cout << tmp[pos];
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
相关推荐
小白程序员成长日记18 分钟前
2025.12.03 力扣每日一题
算法·leetcode·职场和发展
元亓亓亓22 分钟前
LeetCode热题100--20. 有效的括号--简单
linux·算法·leetcode
熊猫_豆豆27 分钟前
LeetCode 49.字母异位组合 C++解法
数据结构·算法·leetcode
ModestCoder_2 小时前
强化学习 Policy 的 Tracking 能力全解析,以Legged_gym为例解说Policy的训练流程
人工智能·算法·自然语言处理·机器人·具身智能
小白程序员成长日记2 小时前
2025.12.02 力扣每日一题
数据结构·算法·leetcode
永远都不秃头的程序员(互关)2 小时前
在vscodeC语言多文件编译实战指南
c语言·数据结构·算法
立志成为大牛的小牛2 小时前
数据结构——五十三、处理冲突的方法——拉链法(王道408)
数据结构·学习·考研·算法
吃着火锅x唱着歌3 小时前
LeetCode 3583.统计特殊三元组
算法·leetcode·职场和发展
FPGA_无线通信3 小时前
OFDM 频偏补偿和相位跟踪(2)
算法·fpga开发
SHOJYS3 小时前
思维难度较大 贪心优化背包 [USACO22DEC] Bribing Friends G
数据结构·算法·深度优先