社区讨论
获得新成就:黄题过百行(P2313)
灌水区参与者 5已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @mi86l9pj
- 此快照首次捕获于
- 2025/11/21 09:28 4 个月前
- 此快照最后确认于
- 2025/11/21 09:28 4 个月前
CPP
/*
Name: P2313
Copyright: Luogu
Author: 9u46
Date: 19/07/19 12:05
Description: https://www.luogu.org/fe/problem/P2313
*/
# include <algorithm>
# include <cctype>
# include <cmath>
# include <cstdio>
# include <vector>
# define Max_N 500
using std::max;
using std::min;
using std::vector;
unsigned short hhdtohu(signed char hhd) {
return hhd - '0';
}
signed char hutohhd(unsigned short hu) {
return hu + '0';
}
void scan(float& a) {
a = 0;
signed char t;
while (not isdigit(t = getchar()));
while (a = a * 10 + hhdtohu(t), isdigit(t = getchar()));
if (t != '.' or !isdigit(t = getchar())) {
return;
}
float u = 0.1;
while (a += hhdtohu(t) * u, u /= 10, isdigit(t = getchar()));
}
void scan(float& a, float& b) {
scan(a), scan(b);
}
void scan(float& a, float& b, float& c) {
scan(a,b), scan(c);
}
void scan(float& a, float& b, float& c, float& d) {
scan(a,b,c), scan(d);
}
void print(unsigned short a) {
signed char t[3];
unsigned short l = 0;
while (t[l++] = hutohhd(a % 10), a /= 10);
while (l--) {
putchar(t[l]);
}
putchar('\n');
}
struct rectangle {
float l, r, u, d;
void input() {
float x1, y1, x2, y2;
scan(x1, y1, x2, y2);
l = min(x1, x2);
r = max(x1, x2);
u = max(y1, y2);
d = min(y1, y2);
}
};
struct cercle {
float x, y, r;
void input() {
scan(x, y, r);
}
};
struct point {
float x, y;
void input() {
scan(x, y);
}
bool in(rectangle r) {
return r.l < x && x < r.r and r.u > y && y > r.d;
}
bool in(cercle c) {
return sqrt(pow(x - c.x, 2) + pow(y - c.y, 2)) < c.r;
}
};
unsigned short N, M;
vector<rectangle> r;
vector<cercle> c;
signed int main(){
scanf("%hu%hu", &N, &M);
for (unsigned short i = 0; i < N; ++i) {
signed char t;
while (t = getchar(), t != 'r' and t != 'c');
switch (t) {
case 'r': {
rectangle t;
t.input();
r.push_back(t);
break;
}
case 'c': {
cercle t;
t.input();
c.push_back(t);
break;
}
}
}
for (unsigned short i = 0; i < M; ++i) {
point t;
t.input();
unsigned short ans = 0;
for (unsigned short j = 0; j < r.size(); ++j) {
if (t.in(r[j])) {
++ans;
}
}
for (unsigned short j = 0; j < c.size(); ++j) {
if (t.in(c[j])) {
++ans;
}
}
print(ans);
}
return 0;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...