1376: Ifrit的家庭作业
题目
题目描述
Ifrit
今天学到了圆的概念,家庭作业中自然都是相关的内容。
但今天Eyjafjalla
约她出去玩,她没有时间写作业了。你能帮帮她吗?
在这道题目中,你需要维护一个结构体数组并按照指令要求进行相关操作。
本题意在为下周一(10.11)上机课的内容做一些知识储备。在这道题目中,你需要自学函数、结构体与指针的基本内容,填充以下示例代码中未完成的部分并确保你明白每一行代码的含义。
你不应该更改todo
以外部分的代码。
```c++
include
include
include
include
using namespace std;
struct Coordinate { double x; double y; };
struct Circle { Coordinate center; double radius; };
const int MAX_NUM = 10000; int circleNumber = 0; // 目前存储的圆的数量 Circle circles[MAX_NUM];
void addCircle(Coordinate center, double radius) { // todo
circleNumber++;
}
void modifyCircle(int index, Coordinate center, double radius) { // todo
}
void printCircle(Circle circle) { // todo
}
bool intersect(Circle circle1, Circle circle2) { // todo
}
void traverse() { // 使用指针遍历数组 for (Circle ptr = circles; ptr != circles + circleNumber; ptr++) { printCircle(ptr); } }
int main() { int op, n; cin >> n; while (n--) { cin >> op; if (op == 1) { double x, y, r; cin >> x >> y >> r; Coordinate center; center.x = x; center.y = y; addCircle(center, r); } else if (op == 2) { int index; double x, y, r; cin >> index >> x >> y >> r; Coordinate center; center.x = x; center.y = y; modifyCircle(index, center, r); } else if (op == 3) { int index; cin >> index; printCircle(circles[index]); } else if (op == 4) { int index1, index2; cin >> index1 >> index2; if (intersect(circles[index1], circles[index2]))cout << "Yes" << endl; else cout << "No" << endl; } else if (op == 5) { traverse(); } } }
```
输入格式
第一行一个整数 $n$ ,代表操作数量。
之后 $n$ 行每行为一个指令,每行第一个数字 $op$ 代表指令类别。格式及含义如下:
op == 1 : 添加一个圆
指令格式:1 x y r
添加一个圆心坐标位于 (x, y) ,半径为 r 的圆
op == 2 : 更改某个圆的属性
指令格式:2 index x y r
将数组中下标为index
的圆信息更新为圆心坐标位于 (x, y) ,半径为 r 。
0-based
并保证index
不会越界。
op == 3 : 输出某个圆的信息
指令格式:3 index
一行,用空格分隔输出圆的 x 坐标、 y 坐标、半径。
0-based
并保证index
不会越界。
op == 4 : 判断某两个圆是否相交
指令格式:4 index1 index2
判断数组中下标为index1
、index2
的两个圆是否相交,输出一行一个单词表示结果。
如果相交输出Yes
,否则输出No
。
0-based
并保证index1
、index2
不会越界。
op == 5 : 输出每个圆的信息
指令格式:5
按照添加的顺序输出每个圆的信息。
输出格式
所有浮点数保留三位小数。
样例输入
6
1 1 1 2
1 0 0 2
3 1
2 1 -1 -1 3
4 0 1
5
样例输出
0.000 0.000 2.000
Yes
1.000 1.000 2.000
-1.000 -1.000 3.000
数据范围
圆的数量 $num<10,000$ ,操作数量 $n<300,000$ 。
圆的坐标、半径绝对值均 $<1000$ 。
Oops! 本题目还没有解答!
助教老师们编题的速度,已经超过了解题的速度!
OJ翻了一新,但本解答集还大多用的是2017-2019级,甚至更早的同学们贡献的答案。
如果你已经AC了,可以的话,请您参考添加页面,与大家一起分享你的题解!