H Mesh Analysis
题意:
给你n个点和m个直线或三角形,以及t个询问,问你当前这个点x在和哪些点在同一直线或同一三角形中和当前这个点在的直线和三角形的编号。
题解:
设定一个唯一的编号,用两个个set来去重的存,一个存当前这个点的临点,一个存当前这个点的所在的直线和三角形的编号。
Code
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <stack>
#include <iomanip>
#include <deque>
#include <sstream>
#define x first
#define y second
using namespace std;
typedef long double ld;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef unsigned long long ULL;
const int N = 1e5 + 10, M = 2 * N, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-8;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int h[N], e[M], ne[M], w[M], idx;
void add(int a, int b, int v = 0) {
e[idx] = b, w[idx] = v, ne[idx] = h[a], h[a] = idx ++;
}
int n, m, k;
int id, a, b, c, op;
double x, y, z;
map<int, int> mp;
set<int> s1[N], s2[N];
void insert_d(int a, int b) { // a到b的直线
if (s1[mp[a]].find(b) == s1[mp[a]].end())
s1[mp[a]].insert(b);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) {
cin >> id;
mp[id] = i;
cin >> x >> y >> z;
}
for (int i = 1; i <= m; i ++ ) {
cin >> id >> op;
if (op == 102) {
cin >> a >> b;
insert_d(a, b), insert_d(b, a);
s2[mp[a]].insert(id), s2[mp[b]].insert(id); // 当前这个点相邻的边和三角形
}
else {
cin >> a >> b >> c;
insert_d(a, b), insert_d(a, c), insert_d(b, a),
insert_d(b, c), insert_d(c, a), insert_d(c, b);
s2[mp[a]].insert(id), s2[mp[b]].insert(id), s2[mp[c]].insert(id);
}
}
int T;
cin >> T;
while (T -- ) {
cin >> id;
if (mp[id] == 0) printf("%d\n[]\n[]\n", id);
else {
printf("%d\n[", id);
for (auto x : s1[mp[id]]) { // 地址的地址
if (x != *s1[mp[id]].begin())
cout << ',';
cout << x;
}
printf("]\n[");
for (auto x : s2[mp[id]]) {
if (x != *s2[mp[id]].begin())
cout << ',';
cout << x;
}
printf("]\n");
}
}
return 0;
}
// 相邻的点,相邻的线和三角形