Circuit Board

本文介绍了一种检测电路板上路径是否交叉的方法,通过跨立实验判断线段相交,确保电路板不会因路径交叉而烧毁。

链接1http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=11851#problem/A 

链接2http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1648 

A - Circuit Board

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %lluSubmit Status Practice ZOJ 1648

Description

On the circuit board, there are lots of circuit paths. We know the basic constrain is that no two path cross each other, for otherwise the board will be burned.

Now given a circuit diagram, your task is to lookup if there are some crossed paths. If not find, print "ok!", otherwise "burned!" in one line.

A circuit path is defined as a line segment on a plane with two endpoints p1(x1,y1) and p2(x2,y2).

You may assume that no two paths will cross each other at any of their endpoints.


Input

The input consists of several test cases. For each case, the first line contains an integer n(<=2000), the number of paths, then followed by n lines each with four float numbers x1, y1, x2, y2.


Output

If there are two paths crossing each other, output "burned!" in one line; otherwise output "ok!" in one line.


Sample Input

1
0 0 1 1

2
0 0 1 1
0 1 1 0


Sample Output

ok!
burned!


解题思路:

判断是否存在两=条线段相交的情况。跨立实验:判断p1p2Q1Q2是否相交则:((p1-Q1×(Q2-Q1))*(Q2-Q1)×(p2-Q1)))>0&&(Q1-p1×(p2-p1))*(p2-p1×(Q2-p1)))>0

#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;

int n;

struct Node

{double x;

double y;

}p[2001][2];

int is_ok(Node p1,Node p2,Node Q1,Node Q2)//判断两条线段是否跨立

{ double a1;

double x1,x2,x3,y1,y2,y3;

x1=p1.x-Q1.x;y1=p1.y-Q1.y;

x2=Q2.x-Q1.x;y2=Q2.y-Q1.y;

x3=p2.x-Q1.x;y3=p2.y-Q1.y;

a1=(x1*y2-x2*y1)*(x2*y3-x3*y2);

if(a1>1e-8)//因为是double 类型,所以要注意精度判断,不能直接与零比较

return 1;

else return 0;

}

int main()

{

 int i,j,ok;

while(scanf("%d",&n)!=EOF)

{for(i=0;i<n;i++)

for(j=0;j<2;j++)

scanf("%lf%lf",&p[i][j].x,&p[i][j].y);

ok=1;

if(n==1)//如果只有一条直线的特殊情况

ok=1;

else

{

for(i=0;i<n;i++)

{if(!ok)break;

for(j=i+1;j<n;j++)

if(is_ok(p[i][0],p[i][1],p[j][0],p[j][1])==1&&is_ok(p[j][0],p[j][1],p[i][0],p[i][1])==1)

{ok=0;break;}

}

}

if(ok)

printf("ok!\n");

else

printf("burned!\n");

}

return 0;

}

import numpy as np import matplotlib.pyplot as plt # ------------------------------- # Font and style setup # ------------------------------- plt.rcParams["font.family"] = "Times New Roman" plt.rcParams["font.size"] = 16 np.random.seed(20251107) # ------------------------------- # Data # ------------------------------- labels = np.array(["Accuracy", "Recall", "F1-score", "mAP@0.5"]) num_vars = len(labels) # Radar data (normalized) circuit_board = np.array([98.1, 96.0, 96.0, 98.4]) / 100.0 ceramic = np.array([97.3, 94.5, 94.0, 97.6]) / 100.0 flexible = np.array([95.8, 93.1, 92.0, 96.1]) / 100.0 # Convergence data scenarios = ["Circuit Board", "Ceramic Substrate", "Flexible Packaging"] convergence_epochs = [15, 15, 15] speedup = [30, 30, 30] # ------------------------------- # Compute radar chart angles # ------------------------------- angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist() angles += angles[:1] # Repeat first value to close radar chart circuit_board = np.concatenate((circuit_board, [circuit_board[0]])) ceramic = np.concatenate((ceramic, [ceramic[0]])) flexible = np.concatenate((flexible, [flexible[0]])) # ------------------------------- # Plot setup (2 subplots) # ------------------------------- fig, axs = plt.subplots(1, 2, figsize=(14, 6), subplot_kw={'projection': [None, 'polar'][1]}) # ------------------------------- # Subplot 1: Radar Chart # ------------------------------- ax = axs[0] = plt.subplot(121, polar=True) colors = ['#2E86AB', '#A23B72', '#F18F01'] line_styles = ['-', '--', '-.'] line_widths = [3, 2.5, 2] ax.plot(angles, circuit_board, linewidth=line_widths[0], linestyle=line_styles[0], label='Circuit Board', color=colors[0], marker='o', markersize=6) ax.fill(angles, circuit_board, alpha=0.4, color=colors[0]) ax.plot(angles, ceramic, linewidth=line_widths[1], linestyle=line_styles[1], label='Ceramic Substrate', color=colors[1], marker='s', markersize=6) ax.fill(angles, ceramic, alpha=0.4, color=colors[1]) ax.plot(angles, flexible, linewidth=line_widths[2], linestyle=line_styles[2], label='Flexible Packaging', color=colors[2], marker='^', markersize=6) ax.fill(angles, flexible, alpha=0.4, color=colors[2]) ax.set_theta_offset(np.pi / 2) ax.set_theta_direction(-1) ax.set_thetagrids(np.degrees(angles[:-1]), labels, fontsize=14) ax.set_ylim(0.9, 1.0) radial_ticks = [0.90, 0.92, 0.94, 0.96, 0.98, 1.00] radial_labels = [f'{tick*100:.0f}%' for tick in radial_ticks] ax.set_yticks(radial_ticks) ax.set_yticklabels(radial_labels, fontsize=12) ax.legend(loc='upper right', bbox_to_anchor=(1.3, 1.0), fontsize=12) ax.grid(True, linestyle='--', alpha=0.7) ax.set_title("Detection Performance Comparison", pad=20) # ------------------------------- # Subplot 2: Bar Chart for Convergence # ------------------------------- ax2 = axs[1] = plt.subplot(122) x = np.arange(len(scenarios)) width = 0.35 bars1 = ax2.bar(x - width/2, convergence_epochs, width, label='Convergence Epochs', color='#2E86AB') bars2 = ax2.bar(x + width/2, speedup, width, label='Speedup (%)', color='#F18F01') ax2.set_xticks(x) ax2.set_xticklabels(scenarios, rotation=15, ha='right') ax2.set_ylabel("Value") ax2.set_ylim(0, 40) ax2.legend(fontsize=12) ax2.set_title("Convergence Speed Comparison", pad=10) ax2.grid(axis='y', linestyle='--', alpha=0.7) # Annotate bars for bars in [bars1, bars2]: for bar in bars: height = bar.get_height() ax2.text(bar.get_x() + bar.get_width()/2, height + 0.8, f'{height:.0f}', ha='center', va='bottom', fontsize=12) plt.tight_layout() plt.show() 修改代码,要求:雷达图将显示指标标签(Accuracy, Recall, F1-score, mAP@0.5)和径向百分比刻度,而不会显示任何角度数值
最新发布
11-08
为了让雷达图显示指标标签和径向百分比刻度,且不显示任何角度数值,需要对原代码进行一些修改。主要是在设置雷达图的角度网格时,去除角度数值的显示。以下是修改后的代码: ```python import numpy as np import matplotlib.pyplot as plt # ------------------------------- # Font and style setup # ------------------------------- plt.rcParams["font.family"] = "Times New Roman" plt.rcParams["font.size"] = 16 np.random.seed(20251107) # ------------------------------- # Data # ------------------------------- labels = np.array(["Accuracy", "Recall", "F1-score", "mAP@0.5"]) num_vars = len(labels) # Radar data (normalized) circuit_board = np.array([98.1, 96.0, 96.0, 98.4]) / 100.0 ceramic = np.array([97.3, 94.5, 94.0, 97.6]) / 100.0 flexible = np.array([95.8, 93.1, 92.0, 96.1]) / 100.0 # Convergence data scenarios = ["Circuit Board", "Ceramic Substrate", "Flexible Packaging"] convergence_epochs = [15, 15, 15] speedup = [30, 30, 30] # ------------------------------- # Compute radar chart angles # ------------------------------- angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist() angles += angles[:1] # Repeat first value to close radar chart circuit_board = np.concatenate((circuit_board, [circuit_board[0]])) ceramic = np.concatenate((ceramic, [ceramic[0]])) flexible = np.concatenate((flexible, [flexible[0]])) # ------------------------------- # Plot setup (2 subplots) # ------------------------------- fig, axs = plt.subplots(1, 2, figsize=(14, 6), subplot_kw={'projection': [None, 'polar'][1]}) # ------------------------------- # Subplot 1: Radar Chart # ------------------------------- ax = axs[0] = plt.subplot(121, polar=True) colors = ['#2E86AB', '#A23B72', '#F18F01'] line_styles = ['-', '--', '-.'] line_widths = [3, 2.5, 2] ax.plot(angles, circuit_board, linewidth=line_widths[0], linestyle=line_styles[0], label='Circuit Board', color=colors[0], marker='o', markersize=6) ax.fill(angles, circuit_board, alpha=0.4, color=colors[0]) ax.plot(angles, ceramic, linewidth=line_widths[1], linestyle=line_styles[1], label='Ceramic Substrate', color=colors[1], marker='s', markersize=6) ax.fill(angles, ceramic, alpha=0.4, color=colors[1]) ax.plot(angles, flexible, linewidth=line_widths[2], linestyle=line_styles[2], label='Flexible Packaging', color=colors[2], marker='^', markersize=6) ax.fill(angles, flexible, alpha=0.4, color=colors[2]) ax.set_theta_offset(np.pi / 2) ax.set_theta_direction(-1) # 设置角度网格只显示标签,不显示角度数值 ax.set_thetagrids(np.degrees(angles[:-1]), labels, fontsize=14) ax.set_ylim(0.9, 1.0) radial_ticks = [0.90, 0.92, 0.94, 0.96, 0.98, 1.00] radial_labels = [f'{tick*100:.0f}%' for tick in radial_ticks] ax.set_yticks(radial_ticks) ax.set_yticklabels(radial_labels, fontsize=12) ax.legend(loc='upper right', bbox_to_anchor=(1.3, 1.0), fontsize=12) ax.grid(True, linestyle='--', alpha=0.7) ax.set_title("Detection Performance Comparison", pad=20) # ------------------------------- # Subplot 2: Bar Chart for Convergence # ------------------------------- ax2 = axs[1] = plt.subplot(122) x = np.arange(len(scenarios)) width = 0.35 bars1 = ax2.bar(x - width/2, convergence_epochs, width, label='Convergence Epochs', color='#2E86AB') bars2 = ax2.bar(x + width/2, speedup, width, label='Speedup (%)', color='#F18F01') ax2.set_xticks(x) ax2.set_xticklabels(scenarios, rotation=15, ha='right') ax2.set_ylabel("Value") ax2.set_ylim(0, 40) ax2.legend(fontsize=12) ax2.set_title("Convergence Speed Comparison", pad=10) ax2.grid(axis='y', linestyle='--', alpha=0.7) # Annotate bars for bars in [bars1, bars2]: for bar in bars: height = bar.get_height() ax2.text(bar.get_x() + bar.get_width()/2, height + 0.8, f'{height:.0f}', ha='center', va='bottom', fontsize=12) plt.tight_layout() plt.show() ``` ### 主要修改点 在设置角度网格时,`ax.set_thetagrids` 函数只传入了角度对应的标签,而没有传入角度数值,这样就不会显示角度数值了。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值