Mesh Analysis

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;
}
// 相邻的点,相邻的线和三角形
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值