三点确定一个圆(Apple HDU - 6206)(计算几何+高精度)

article/2025/11/6 22:41:33

传送门

三点确定一个圆的计算方法

设一个圆的圆心坐标为(x0,y),半径为r。那么这个圆的方程可以写成

(x-x0)^2+(y-y0)^2=r^2

在这个圆上随便取三个点,设这三个点的坐标分别为(x1,y1),(x2,y2),(x3,y3)。那么有

公式(1)(2)相减,(1)(3)相减经过化简可以得到:

x0,y0有唯一解的条件是系数行列式不为0:

简单变形就是:

这样也就是三点不能共线

设:

那么结果

这样答案就出来了

 

题解 :先判断出圆心的位置,然后进而算出半径的大小,最后跟据最后一个点与这个圆心的距离进行判断大小,还使用了个大大大的大整数类,不会JAVA,赶快学


#include<bits/stdc++.h>#define MAX_L 2005 //最大长度,可以修改using namespace std;#define max_n 100000000//因为结果可能不是整数,把小数部分去掉class bign
{
public:int len, s[MAX_L];//数的长度,记录数组
//构造函数bign();bign(const char*);bign(int);bool sign;//符号 1正数 0负数string toStr() const;//转化为字符串,主要是便于输出friend istream& operator>>(istream &,bign &);//重载输入流friend ostream& operator<<(ostream &,bign &);//重载输出流
//重载复制bign operator=(const char*);bign operator=(int);bign operator=(const string);
//重载各种比较bool operator>(const bign &) const;bool operator>=(const bign &) const;bool operator<(const bign &) const;bool operator<=(const bign &) const;bool operator==(const bign &) const;bool operator!=(const bign &) const;
//重载四则运算bign operator+(const bign &) const;bign operator++();bign operator++(int);bign operator+=(const bign&);bign operator-(const bign &) const;bign operator--();bign operator--(int);bign operator-=(const bign&);bign operator*(const bign &)const;bign operator*(const int num)const;bign operator*=(const bign&);bign operator/(const bign&)const;bign operator/=(const bign&);
//四则运算的衍生运算bign operator%(const bign&)const;//取模(余数)bign factorial()const;//阶乘bign Sqrt()const;//整数开根(向下取整)bign pow(const bign&)const;//次方
//一些乱乱的函数void clean();~bign();
};#define max(a,b) a>b ? a : b
#define min(a,b) a<b ? a : bbign::bign()
{memset(s, 0, sizeof(s));len = 1;sign = 1;
}bign::bign(const char *num)
{*this = num;
}bign::bign(int num)
{*this = num;
}string bign::toStr() const
{string res;res = "";for (int i = 0; i < len; i++)res = (char)(s[i] + '0') + res;if (res == "")res = "0";if (!sign&&res != "0")res = "-" + res;return res;
}istream &operator>>(istream &in, bign &num)
{string str;in>>str;num=str;return in;
}ostream &operator<<(ostream &out, bign &num)
{out<<num.toStr();return out;
}bign bign::operator=(const char *num)
{memset(s, 0, sizeof(s));char a[MAX_L] = "";if (num[0] != '-')strcpy(a, num);elsefor (int i = 1; i < strlen(num); i++)a[i - 1] = num[i];sign = !(num[0] == '-');len = strlen(a);for (int i = 0; i < strlen(a); i++)s[i] = a[len - i - 1] - 48;return *this;
}bign bign::operator=(int num)
{char temp[MAX_L];sprintf(temp, "%d", num);*this = temp;return *this;
}bign bign::operator=(const string num)
{const char *tmp;tmp = num.c_str();*this = tmp;return *this;
}bool bign::operator<(const bign &num) const
{if (sign^num.sign)return num.sign;if (len != num.len)return len < num.len;for (int i = len - 1; i >= 0; i--)if (s[i] != num.s[i])return sign ? (s[i] < num.s[i]) : (!(s[i] < num.s[i]));return !sign;
}bool bign::operator>(const bign&num)const
{return num < *this;
}bool bign::operator<=(const bign&num)const
{return !(*this>num);
}bool bign::operator>=(const bign&num)const
{return !(*this<num);
}bool bign::operator!=(const bign&num)const
{return *this > num || *this < num;
}bool bign::operator==(const bign&num)const
{return !(num != *this);
}bign bign::operator+(const bign &num) const
{if (sign^num.sign){bign tmp = sign ? num : *this;tmp.sign = 1;return sign ? *this - tmp : num - tmp;}bign result;result.len = 0;int temp = 0;for (int i = 0; temp || i < (max(len, num.len)); i++){int t = s[i] + num.s[i] + temp;result.s[result.len++] = t % 10;temp = t / 10;}result.sign = sign;return result;
}bign bign::operator++()
{*this = *this + 1;return *this;
}bign bign::operator++(int)
{bign old = *this;++(*this);return old;
}bign bign::operator+=(const bign &num)
{*this = *this + num;return *this;
}bign bign::operator-(const bign &num) const
{bign b=num,a=*this;if (!num.sign && !sign){b.sign=1;a.sign=1;return b-a;}if (!b.sign){b.sign=1;return a+b;}if (!a.sign){a.sign=1;b=bign(0)-(a+b);return b;}if (a<b){bign c=(b-a);c.sign=false;return c;}bign result;result.len = 0;for (int i = 0, g = 0; i < a.len; i++){int x = a.s[i] - g;if (i < b.len) x -= b.s[i];if (x >= 0) g = 0;else{g = 1;x += 10;}result.s[result.len++] = x;}result.clean();return result;
}bign bign::operator * (const bign &num)const
{bign result;result.len = len + num.len;for (int i = 0; i < len; i++)for (int j = 0; j < num.len; j++)result.s[i + j] += s[i] * num.s[j];for (int i = 0; i < result.len; i++){result.s[i + 1] += result.s[i] / 10;result.s[i] %= 10;}result.clean();result.sign = !(sign^num.sign);return result;
}bign bign::operator*(const int num)const
{bign x = num;bign z = *this;return x*z;
}
bign bign::operator*=(const bign&num)
{*this = *this * num;return *this;
}bign bign::operator /(const bign&num)const
{bign ans;ans.len = len - num.len + 1;if (ans.len < 0){ans.len = 1;return ans;}bign divisor = *this, divid = num;divisor.sign = divid.sign = 1;int k = ans.len - 1;int j = len - 1;while (k >= 0){while (divisor.s[j] == 0) j--;if (k > j) k = j;char z[MAX_L];memset(z, 0, sizeof(z));for (int i = j; i >= k; i--)z[j - i] = divisor.s[i] + '0';bign dividend = z;if (dividend < divid) { k--; continue; }int key = 0;while (divid*key <= dividend) key++;key--;ans.s[k] = key;bign temp = divid*key;for (int i = 0; i < k; i++)temp = temp * 10;divisor = divisor - temp;k--;}ans.clean();ans.sign = !(sign^num.sign);return ans;
}bign bign::operator/=(const bign&num)
{*this = *this / num;return *this;
}bign bign::operator%(const bign& num)const
{bign a = *this, b = num;a.sign = b.sign = 1;bign result, temp = a / b*b;result = a - temp;result.sign = sign;return result;
}bign bign::pow(const bign& num)const
{bign result = 1;for (bign i = 0; i < num; i++)result = result*(*this);return result;
}bign bign::factorial()const
{bign result = 1;for (bign i = 1; i <= *this; i++)result *= i;return result;
}void bign::clean()
{if (len == 0) len++;while (len > 1 && s[len - 1] == '\0')len--;
}bign bign::Sqrt()const
{if(*this<0)return -1;if(*this<=1)return *this;bign l=0,r=*this,mid;while(r-l>1){mid=(l+r)/2;if(mid*mid>*this)r=mid;elsel=mid;}return l;
}bign::~bign()
{
}
int main() {bign x,y,x1,x2,x3,y1,y2,y3,x4,y4;bign a,b,c,d,e,f;bign ling=0;int t;bign dis;bign tes;cin>>t;while(t--){cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;x1=x1*max_n;y1=y1*max_n;x2=x2*max_n;y2=y2*max_n;y3=y3*max_n;x3=x3*max_n;x4=x4*max_n;y4=y4*max_n;a=x1-x2;b=y1-y2;c=x1-x3;d=y1-y3;e=(x1*x1-x2*x2-y2*y2+y1*y1)/2;f=(x1*x1-x3*x3-y3*y3+y1*y1)/2;x= (d*e-b*f)/(b*c-a*d);y= (a*f-c*e)/(b*c-a*d);dis=(x+x1)*(x+x1)+(y+y1)*(y+y1);tes=(x+x4)*(x+x4)+(y+y4)*(y+y4);if(dis<tes)printf("Accepted\n");elseprintf("Rejected\n");}return 0;
}

 


http://chatgpt.dhexx.cn/article/e5Qb1Zax.shtml

相关文章

与圆有关的位置关系

与圆有关的位置关系 主讲&#xff1a;黄冈中学高级教师 余国琴 知识强化 一、知识概述 1、点和圆的位置关系 如果圆的半径为r&#xff0c;已知点到圆心的距离为d&#xff0c;则可用数量关系表示位置关系&#xff0e; (1)d&#xff1e;r点在圆外&#xff1b; (2)dr点在圆上&a…

三点定圆原理与C++实现

文章目录 1 原理2 C实现 1 原理 根据我们小学二年级就学过的三点定圆定理&#xff1a; 不 共 线 的 三 个 点 可 唯 一 确 定 一 个 圆 不共线的三个点可唯一确定一个圆 不共线的三个点可唯一确定一个圆 且&#xff0c;不共线的三点相互连接必然构成一个三角形&#xff0c;这…

使用C语言实现简单的PNG图像读取

概述 首先&#xff0c;关于png图像的结构&#xff1a;PNG文件的结构、PNG格式的数据结构。这两篇文章说的比较细。我简单地说一下我使用到的地方&#xff1a; 注&#xff1a;①引于PNG格式的数据结构。②引于PNG文件的结构 “png文件的前8个字节为固定的文件头信息&#xff0…

RK3588平台开发系列讲解(Display篇)开机视频的设置

平台内核版本安卓版本RK3588Linux 5.10Android 12文章目录 一、开机视频功能介绍二、使用方法2.1、开启与关闭2.2、视频放置位置2.3、编译结果2.4、视频素材要求2.5、参数控制说明沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇将介绍RK3588平台开机视频的使用方法…

NR PUCCH(一) PUCCH format 0/1

欢迎关注同名微信公众号“modem协议笔记”。 NR中PUCCH物理信道用来发送上行控制信息Uplink Control Information(UCI)&#xff0c;当然UCI也可以在PUSCH上发送。UCI 内容包括&#xff1a;CSI,HARQ ACK/NACK ,SR 及上述三者的组合信息。 那先看下PUCCH format &#xff0c;序…

NR PUSCH(三) 频域资源分配方式

微信公众号同步更新欢迎关注同名modem协议笔记 这篇看下频域资源分配&#xff0c;本篇内容主要在38.214 6.1.2.2 resource allocation in frequency domain章节中。 相比于R15&#xff0c;R16 频域资源分配有3种类型 Uplink resource allocation scheme type 0/1/2&#xff08…

NR PUSCH(四) Frequency hopping

微信公众号同步更新&#xff0c;欢迎关注同名modem协议笔记 上篇PUSCH 介绍了频域分配方式resource allocation type0/1/2&#xff0c;其中type 0 RBG位图的分配方式比较灵活&#xff0c;type 2对应的interlaced RB 本身就是一种频域的离散化&#xff0c;都可以实现类似的效果…

halcon中阈值分割算子用法

1.threshold(Image : Region : MinGray, MaxGray : )&#xff1a;通过给定的阈值区间对图像进行分割 效果图&#xff1a; read_image (Audi2, audi2) fill_interlace (Audi2, ImageFilled, odd) threshold (ImageFilled, Region, 0, 90) 2.binary_threshold(Image : Region : …

De-interlace 反交错 简介

<script type"text/javascript"> </script> <script type"text/javascript"> </script> 为了更好的理解新的逐行扫瞄的概念&#xff0c;必须先弄清楚电视传输的一些基本知识&#xff0c;一副图像是如何传输的&#xff0c;它与新的…

pygame加载png出现known incorrect sRGB,Interlace handling should be turned on when using png_read_image问题

使用pygame加载png出现libpng warning: iCCP: known incorrect sRGB profile和Interlace handling should be turned on when using png_read_image警告的问题 一、解决Interlace handling should be turned on when using png_read_image警告 最近使用Python实现强化学习走迷…

计算机视觉之旅(Day3)

对不起大家&#xff0c;opencv的坑我尽量在年底更完&#xff0c;C的坑已经基本更完了&#xff0c;在没有进一步深入学习C之前可能这个系列已经算完了。不多说&#xff0c;我看看机器视觉的基本内容吧。 &#xff08;一&#xff09;基本构成 传统的机器视觉系统是由待测目标、…

交错(拉丝)(Interlace) 与 反胶卷过带

第一部分——交错&#xff08;拉丝&#xff09;&#xff08;Interlace&#xff09;的产生 引用了相当多网友的分析与结论&#xff0c;恕我不能依次注明。分析主要来自“[SilkyBible] 视频知识系列”&#xff0c;就主要概念的主要影响因素进行了一点分析。如果有错误&#xff0c…

二分法之最大子段和

1.问题描述&#xff1a;给定一个数组&#xff0c;找出其中可以构成最大数的子段&#xff0c;子段和是由连续的子段构成的&#xff1b;给定有n个整数(可能为负整数)组成的序列a1,a2,...,an,求该序列连续的子段和的最大值。 2.设计思路&#xff1a;对于一个连续的子段和&#xf…

java动态规划求最大子段和_动态规划-最大子段和

2018-01-14 21:14:58 一、最大子段和问题 问题描述&#xff1a;给定n个整数(可能有负数)组成的序列a1&#xff0c;a2&#xff0c;...&#xff0c;an&#xff0c;求该序列的最大子段和。如果所有整数都是负数&#xff0c;那么定义其最大子段和为0。 方法一、最大子段和的简单算法…

四种方法求解最大子段和问题

题目描述 给定一段长度为n的序列&#xff0c;我们需要找到其中一个连续的子段&#xff0c;使这个子段中各个元素加和最大&#xff0c;如果这个数组中全为负整数&#xff0c;我们就定义这个子段和为0. 题目分析 首先我们的目的是找一个局部的子段但加和是全局最大&#xff0c;…

最大子段和问题(分治法和动态规划)

什么是最大子段和&#xff0c;通俗点讲&#xff1a; 最大子段和就是给了一些数&#xff0c;然后你从中找了几个连续的数&#xff0c;这组连续的数的和比任意一组连续的数的和都大&#xff0c;那么你找的这几个连续的数的和就是这些数的最大子段和。 通俗的听不懂你就看这里&am…

最大子段求和

3种算法&#xff1a;最大子段求和 一、问题分析 问题&#xff1a;给定有n个整数(可能为负整数)组成的序列 a 1 , a 2 , . . . , a n , a_1,a_2,...,a_n, a1​,a2​,...,an​,求该序列连续的子段和的最大值。 如果该子段的所有元素和是负整数时定义其最大子段和为0。 简易算法…

最大子段和问题(3种方法)

给定由n个整数(可能为负整数)组成的序列a1&#xff0c;a2&#xff0c; a3… &#xff0c; an&#xff0c; 寻找它的某个连续子段&#xff0c;使得其和最大。例如( -2,11,-4,13,-5,-2 )最大子段是{ 11,-4,13 }其和为20。 1、最大字段和问题的简单算法 (1)枚举法求解&#xff1…

最大子段和(动态规划算法)

最大子段和&#xff08;动态规划算法&#xff09; 文章目录 最大子段和&#xff08;动态规划算法&#xff09;一、思路二、伪代码三、C代码四、输入实例 一、思路 D[i]表示从i开始的最大字段和。&#xff08;但我们不是从前往后找字段结束位置&#xff09; 根据递推公式&#x…

最大子段和——用蛮力算法,分治策略,动态规划算法三种求法(C语言)

目录 一、题目 二、算法求解 1、蛮力算法 伪代码 算法分析 程序 2、分治策略 伪代码 算法分析 程序 3、动态规划算法 伪代码 算法分析 程序 一、题目 设A<a1,a2,...,an>是n个整数的序列&#xff0c;称<ai,....,aj>为该序列的连续子序列&#xff0c;其…