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");
}
}