D. Tetragon

D. Tetragon
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You're given the centers of three equal sides of a strictly convex tetragon. Your task is to restore the initial tetragon.

Input

The first input line contains one number T — amount of tests (1 ≤ T ≤ 5·104). Each of the following T lines contains numbers x1, y1, x2, y2, x3, y3 — coordinates of different points that are the centers of three equal sides (non-negative integer numbers, not exceeding 10).

Output

For each test output two lines. If the required tetragon exists, output in the first line YES, in the second line — four pairs of numbers — coordinates of the polygon's vertices in clockwise or counter-clockwise order. Don't forget, please, that the tetragon should be strictly convex, i.e. no 3 of its points lie on one line. Output numbers with 9 characters after a decimal point.

If the required tetragon doen't exist, output NO in the first line, and leave the second line empty.

Sample test(s)
Input
3
1 1 2 2 3 3
0 1 1 0 2 2
9 3 7 9 9 8
Output
NO

YES
3.5 1.5 0.5 2.5 -0.5 -0.5 2.5 0.5
NO


解释:

设ABCD是所寻求的四边形,和K,L和M是相等的边AB,BC和CD,相应的中间点。让,M'是对称的点相对于L。然后BM'= CM = CL = BL = BK,我到M。 E。 B是三角形的KLM'外心。

了解B,我们可以得到整个四合院,使用的对称性点,K,L和M,然后检查它是否满足所有的条件。
需要注意的是,我们不知道哪一个给定的点是L,所以我们需要检查所有的3起案件。

代码:

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

struct point
{
    double x,y;
};

#define eps 1.0E-9
#define _abs(x) ((x)>0?(x):-(x))

double area(point P, point Q, point R)
{
    return ((Q.x - P.x) * (R.y - P.y) - (Q.y - P.y) * (R.x - P.x)) / 2.0;
}

point cross(point A, point B, point C, point D)  // AB - CD
{
    double a = -A.y + B.y, b = A.x - B.x, c = A.x * B.y - A.y * B.x, d = -C.y + D.y, e = C.x - D.x, f = C.x * D.y - C.y * D.x;
    point ans = {(c*e - b*f) / (a*e - b*d), (c*d - a*f) / (b*d - a*e)};
    return ans;
}

point func4(point &P, point &M)
{
    point ans = {M.x * 2 - P.x, M.y * 2 - P.y};
    return ans;
}

point func3(point &A, point &B)
{
    double dx = B.x - A.x, dy = B.y - A.y;
    point ans = {A.x + dx / 2.0 - dy / 2.0, A.y + dy / 2.0 + dx / 2.0};
    return ans;
}

vector <point> func2(point A, point B, point C)
{
    point D,E,F,G;

    point H = func3(A,B), I = func3(B,A);
    double dx = B.x - A.x, dy = B.y - A.y;
    H.x += dx;
    H.y += dy;
    I.x += dx;
    I.y += dy;
    point J = func3(B,C), K = func3(C,B);
    E = cross(H,I,J,K);
    D = func4(E,C);
    F = func4(E,B);
    G = func4(F,A);

    vector <point> ans;
    double tmp;
    bool pos = false, neg = false;
    tmp = area(D,E,F);
    if(tmp > -eps) pos = true;
    if(tmp < eps) neg = true;
    tmp = area(E,F,G);
    if(tmp > -eps) pos = true;
    if(tmp < eps) neg = true;
    tmp = area(F,G,D);
    if(tmp > -eps) pos = true;
    if(tmp < eps) neg = true;
    tmp = area(G,D,E);
    if(tmp > -eps) pos = true;
    if(tmp < eps) neg = true;
    if(pos && neg) return ans;
    ans.push_back(D);
    ans.push_back(E);
    ans.push_back(F);
    ans.push_back(G);
    return ans;
}

vector <point> func(point A, point B, point C)
{
    vector <point> ans;
    if(_abs(area(A,B,C)) < eps) return ans;
    ans = func2(A,B,C);
    if(!ans.empty()) return ans;
    ans = func2(B,C,A);
    if(!ans.empty()) return ans;
    ans = func2(C,A,B);
    if(!ans.empty()) return ans;
    return ans;
}

int main(void)
{
    int T,t,i;
    point A,B,C;

    scanf("%d",&T);
    REP(t,T)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);
        vector <point> ans = func(A,B,C);
        if(!ans.empty()) printf("YES\n");
        else printf("NO\n");
        REP(i,ans.size())
        {
            printf("%.9f %.9f",ans[i].x,ans[i].y);
            if(i != ans.size() - 1) printf(" ");
        }
        printf("\n");
    }

    return 0;
}


<think>好的,我需要回答用户关于Kubernetes日志收集方式的问题。用户之前问过关于ArgoCD权限设置的问题,现在转向Kubernetes的日志收集,可能是在搭建或维护云原生环境,需要了解不同日志管理方案。 首先,我得回忆Kubernetes日志收集的常见方法。用户可能希望了解各种方案的优缺点以及适用场景,所以需要结构清晰的分类,比如节点级、应用级、边车容器等。 然后,考虑用户可能的背景。他们可能是DevOps工程师或系统管理员,需要实际操作的步骤或工具推荐。可能需要涵盖开源工具和商业方案,如Fluentd、Elasticsearch、Loki、商业产品如Datadog等。 接下来,要确保回答覆盖主要方面:日志类型(容器日志、控制平面日志)、收集方式(DaemonSet、Sidecar)、存储和分析工具。同时,要提到每个方法的优缺点,比如资源消耗、配置复杂度、扩展性等。 还需要注意用户可能的深层需求,比如如何选择适合自己环境的方案,是否需要考虑成本、易用性、集成能力等。可能需要提供一些最佳实践或选择建议。 另外,检查是否需要提及Kubernetes自身的日志机制,如kubectl logs命令,但用户可能更关注集群级别的收集和集中管理,而不是单Pod的日志查看。 最后,确保语言清晰,步骤详细,结构合理,帮助用户逐步理解不同方案,并根据自己的需求做出选择。可能还需要注意排版,使用列表、标题等让内容易于阅读。</think>以下是 Kubernetes 日志收集的常见方式及其核心实现原理,按技术类型分类整理: --- ### 一、基础日志架构分类 #### 1. **节点级收集 (Node-Level Logging)** ```bash /var/log/containers/*.log # 容器标准输出日志存储路径 ``` **实现方式**: - 部署日志代理(DaemonSet模式) - 每个节点运行一个日志采集Pod - 自动收集所有容器标准输出日志 **工具方案**: - Fluentd + Elasticsearch + Kibana (EFK) - Filebeat + Logstash + Elasticsearch (ELK) - Promtail + Loki + Grafana (PLG) **性能公式**: 日志处理吞吐量 = 节点数 × (单节点Pod密度 × 日志生成速率) 建议单节点配置:2核CPU + 4GB内存(Fluentd) --- #### 2. **应用级日志收集** **场景特征**: - 需要结构化日志 - 日志输出到文件而非标准输出 - 多容器Pod需要独立日志流 **实现方案**: ```yaml # Sidecar容器配置示例 containers: - name: app image: my-app volumeMounts: - name: log-volume mountPath: /var/log/app - name: log-sidecar image: fluentd volumeMounts: - name: log-volume mountPath: /var/log/app ``` **技术选型**: - Vector.dev(高性能Rust实现) - OpenTelemetry Collector(CNCF标准) --- ### 三、控制平面日志 **关键组件**: ```text kube-apiserver audit logs # API访问审计 kube-controller-manager logs # 控制循环日志 kube-scheduler logs # 调度决策日志 ``` **收集方式**: - 直接对接云厂商日志服务(AWS CloudWatch, GCP Stackdriver) - 自定义配置journald收集系统服务日志 --- ### 四、高级收集策略 #### 1. **日志路由标记** ```yaml annotations: logging.alpha.kubernetes.io/tags: "env=prod,app=payment" ``` #### 2. **多级缓冲配置** ```text 应用容器 -> local buffer -> Kafka -> 日志处理集群 ``` **推荐配置**: - 节点级使用Fluentd进行初步过滤 - Kafka保留策略:按业务关键性设置1-7天 - 最终存储使用Elasticsearch ILM策略 --- ### 五、主流技术栈对比 | 方案 | 吞吐量 | 资源消耗 | 查询能力 | 学习曲线 | 适用场景 | |----------------------|-----------|----------|----------------|----------|--------------------------| | EFK | 高 | 高 | 强(ES语法) | 陡峭 | 企业级复杂分析 | | PLG(Loki) | 非常高 | 低 | LogQL | 中等 | 云原生环境 | | Datadog | 自动扩展 | 按需付费 | 可视化最佳 | 简单 | SaaS优先团队 | | Splunk | 极高 | 非常高 | 企业级分析 | 复杂 | 金融/医疗等强合规领域 | --- ### 六、性能优化公式 **日志索引效率**: $$ \text{索引速率} = \frac{\text{可用内存(GB)} \times 0.25}{平均日志大小(KB)} \times 1000 $$ **存储计算**: 每日存储量 = 日志条数 × 平均大小 × 副本数 × 压缩比(通常0.2) --- ### 七、安全合规要求 1. **日志脱敏**:使用正则过滤信用卡号等敏感信息 2. **访问控制**: ```yaml # Elasticsearch角色配置示例 { "indices": [{ "names": ["logs-*"], "privileges": ["read"], "field_security": {"except": ["credit_card"]} }] } ``` 3. **保留策略**: - 开发环境:7天 - 生产环境:根据行业法规设定(如GDPR要求6个月) --- ### 八、故障排查命令 ```bash # 查看日志收集延迟 kubectl top pod -n logging | grep fluentd # 检查Elasticsearch健康状态 curl -XGET 'http://elasticsearch:9200/_cluster/health?pretty' # Loki日志查询样例 logcli query '{namespace="production"}|~"error"' ``` --- ### 九、新兴技术趋势 1. **eBPF日志采集**: - Cilium Tetragon - 零侵入采集系统调用日志 2. **WASM插件架构**: - Envoy WASM过滤器处理日志 - 实现边缘计算场景的日志预处理 --- 根据业务规模选择方案: - **初创团队**:直接使用云厂商托管服务(如AWS OpenSearch) - **混合云环境**:采用Loki实现多云日志统一 - **金融级需求**:Splunk + 自建Elasticsearch双备份架构
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值