H Mesh Analysis

11 篇文章 1 订阅
9 篇文章 0 订阅

In computer graphics (CG), it is general to use a triangle mesh to represent the surface of an object.
The 3-D points in a CG program form multiple connected line segments and triangles, which are in turn organized as a triangle mesh. You are asked to find the neighboring points of a given point, as well as the elements (line segments and triangles) that this point belongs to. whose vertex sets this point belongs to. Its neighboring points are the ones that belong to the same vertex set of a line segment or a triangle.
Input
The first line has two integers N and M, the number of 3-D points and the number of elements.
Then N lines follow. Each line consists of one integer and three real numbers, representing the id and the (x, y, z) coordinates of a 3-D point. The real numbers may be in the normal notation or the scientific notation.
Then M lines follow. Each line may consist of four to five integers. The first integer is the element id. The second integer is 102 or 203, a code for segment or triangle, respectively. If it is a segment (i.e., 102), there are two more integers indicating the id of the two endpoints; and if it is a triangle (i.e., 203), there are three more integers indicating the id of the three vertices.
Then there is an integer L, the number of queries.
Finally, L lines follow. Each line has an integer, representing the point id to query.
1≤N≤10000,1≤M≤21000,1≤L≤10,−10 9 ≤q i​ ≤10 9 .
Note: You may use std::cin to read in the real numbers.
Output
Print L sections, one for each query.
Each section consists of three lines: The first line is the point id. The second line is the list of its neighboring points. And the third line is the list of elements that this point belongs to.
The list elements are printed in numerical order with square brackets and separated by commas. An empty list is [].

前边的坐标输入具有迷惑性,所以直接将前n行值全部舍去‘
然后用set存储动态数组(自动实现排序与去重)

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
using namespace std;
map<int, set<int >> mp1,mp2;
int main()
{
    int n,m;
    cin>>n>>m;
    int a;
    double q,w,e;
    while(n--)
    {
        scanf("%d%lf%lf%lf",&a,&q,&w,&e);
    }
    int x,y,z;
    int i,s;
    while(m--)
    {
        scanf("%d%d",&i,&s);
        if(s==203)
        {
            scanf("%d%d%d",&x,&y,&z);
            mp1[x].insert(y);
            mp1[x].insert(z);
            mp1[y].insert(x);
            mp1[y].insert(z);
            mp1[z].insert(x);
            mp1[z].insert(y);
            mp2[x].insert(i);
            mp2[y].insert(i);
            mp2[z].insert(i);
        }
        else
        {
            scanf("%d%d",&x,&y);
            mp1[x].insert(y);
            mp1[y].insert(x);
            mp2[x].insert(i);
            mp2[y].insert(i);
        }
    }
    cin>>m;
    while(m--)
    {
        scanf("%d",&n);
        printf("%d\n[",n);
        int f=0;
        for(auto &t:mp1[n])//遍历mp1[n]set数组
        {
            if(f!=0)
                cout<<',';
            cout<<t;
            f=1;
        }
        printf("]\n");
        printf("[");
        f=0;
        for(auto &t:mp2[n])
        {
            if(f!=0)
                cout<<',';
            cout<<t;
            f=1;
        }
        printf("]\n");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Prime me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值