POJ 3792 Area of Polycubes 解题报告
2013-09-21 22:51
337 查看
没有看网上别的解题报告,直接O(n^2)的时间复杂度,倒也直接accept了。
对每个新加入的方块,考虑其与之前的每个方块的“距离”,如果为0,则不正确(因为重叠了);如果遍历完了,没有一个为1的,则也不正确(与之前的连不起来)。否则,正确。
对两点之间距离的定义,这里应该是个欧几里德距离,但是考虑到我们只考虑是否为0或1,因而将坐标之差绝对值相加即可,运算相对简单些。
代码如下:
对每个新加入的方块,考虑其与之前的每个方块的“距离”,如果为0,则不正确(因为重叠了);如果遍历完了,没有一个为1的,则也不正确(与之前的连不起来)。否则,正确。
对两点之间距离的定义,这里应该是个欧几里德距离,但是考虑到我们只考虑是否为0或1,因而将坐标之差绝对值相加即可,运算相对简单些。
代码如下:
// Area of Polycubes #include <iostream> using namespace std; const int MAXP = 100; int dis(int *p1, int *p2) { int d = 0; for(int i = 0; i < 3; ++i) { d += abs(p1[i] - p2[i]); } return d; } int main() { int N; cin>>N; int points[MAXP][3]; for(int no = 0; no < N; ++no) { int P; cin>>P; fscanf(stdin, "%d,%d,%d", &points[0][0], &points[0][1], &points[0][2]); int area = 6; bool iscorrect = true; cout<<no + 1<<" "; for(int i = 1; i < P; ++i) { fscanf(stdin, "%d,%d,%d", &points[i][0], &points[i][1], &points[i][2]); if(!iscorrect) { continue; } area += 6; int j = 0; bool isconnected = false; while(j < i) { int d = dis(points[i], points[j]); if(d == 0) { break; } if(d == 1) { isconnected = true; area -= 2; } j++; } if(j != i || !isconnected) { iscorrect = false; cout<<"NO "<<i + 1<<endl; } } if(iscorrect) { cout<<area<<endl; } } return 0; }
相关文章推荐
- Area of Polycubes poj 3792
- poj 3792 Area of Polycubes (简单模拟)
- poj 3792 Area of Polycubes
- POJ 3792 Area of Polycubes(思维)
- POJ 3792 Area of Polycubes(模拟)
- POJ-3083 Children of the Candy Corn 解题报告
- POJ-3083 Children of the Candy Corn 解题报告
- LA-3415 & POJ-2771 Guardian of Decency 解题报告
- LA-3399 & POJ-2739 Sum of Consecutive Prime Numbers 解题报告
- 南邮 OJ 1537 G ? Area of Polycubes
- liveoj 4238 - Area of Polycubes(搜索)
- 【原】 POJ 2739 Sum of Consecutive Prime Numbers 筛素数+积累数组 解题报告
- POJ-3083 Children of the Candy Corn 解题报告(搜索) 广搜深搜走迷宫
- Area of Polycubes
- POJ 3083 Children of the Candy Corn (DFS+BFS) -- 解题报告
- poj 1265-Area解题报告
- poj 3083 Children of the Candy Corn 解题报告-- DFS BFS
- POJ-3358-Period of an Infinite Binary Expansion 解题报告
- POJ 3792 Area of Polycubes 已被翻译
- Polya 定理 (附POJ 1286 Necklace of Beads 解题报告)