POJ 1021 人品题
报告见代码。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAX=;
int dir[][]={,,-,,,,,-};
int h,w,n;
int maze[MAX][MAX];
int maze2[MAX][MAX];
struct{
int x,y;
}save[];
int sa;
int h1[];
int h2[]; void dfs(int i,int j,int (*p)[MAX]){
p[i][j]=;
save[++sa].x=i;save[sa].y=j;
for(int k=;k<;k++){
int tx,ty;
tx=i+dir[k][];
ty=j+dir[k][];
if(p[tx][ty]==&&tx<h&&tx>=&&ty<w&&ty>=)
dfs(tx,ty,p);
}
} void calculate(int *ha,int &top){ //HASH函数是各点对的距离的平方。。。也过。
int i,j,x=,y=; top++;
for(i=;i<=sa;i++){
x=save[i].x;
y=save[i].y;
for(j=i+;j<=sa;j++){
int dx=abs(x-save[j].x);
int dy=abs(y-save[j].y);
int dis=dx*dx+dy*dy;
ha[top]+=dis;
}
}
} void slove(int (*p)[MAX],int *ha,int &top){
int i,j;
for(i=;i<h;i++){
for(j=;j<w;j++){
sa=;
if(p[i][j]==){
dfs(i,j,p);
calculate(ha,top);
}
}
}
} int main(){
int x,y,cas;
scanf("%d",&cas);
while(cas--){
scanf("%d%d%d",&w,&h,&n);
memset(maze,,sizeof(maze));
memset(maze2,,sizeof(maze2));
memset(h1,,sizeof(h1));
memset(h2,,sizeof(h2));
int top1=-,top2=-;
for(int i=;i<=n;i++){
scanf("%d%d",&x,&y);
maze[y][x]=;
}
/* for(int i=0;i<h;i++){
for(int j=0;j<w;j++)
printf("%d ",maze[i][j]);
printf("\n");
}*/
for(int i=;i<=n;i++){
scanf("%d%d",&x,&y);
maze2[y][x]=;
}
/* for(int i=0;i<h;i++){
for(int j=0;j<w;j++)
printf("%d ",maze2[i][j]);
printf("\n");
}*/
slove(maze,h1,top1);
slove(maze2,h2,top2);
if(top1!=top2){
printf("NO\n");
continue;
}
bool flag=true;
sort(h1,h1+top1+);
sort(h2,h2+top2+);
for(int i=;i<=top1;i++){
// printf("%d %d \n",h1[i],h2[i]);
if(h1[i]!=h2[i]){
flag=false;
break;
}
}
if(!flag)
printf("NO\n");
else
printf("YES\n");
}
return ;
}
POJ 1021 人品题的更多相关文章
- POJ推荐50题
此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...
- 最短路+线段交 POJ 1556 好题
// 最短路+线段交 POJ 1556 好题 // 题意:从(0,5)到(10,5)的最短距离,中间有n堵墙,每堵上有两扇门可以通过 // 思路:先存图.直接n^2来暴力,不好写.分成三部分,起点 终 ...
- (转)poj算法做题顺序
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj329 ...
- poj 1742(好题,楼天城男人八题,混合背包)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 33269 Accepted: 11295 Descripti ...
- poj万人题
poj提交数量过万的题,除了水爆了的题就是无比经典的,不得不刷的题. 准备将poj上提交次数过万的题刷个遍. 持续更新中... poj 2828(线段树) 此题乃是Zhu, Zeyuan神牛出的,拿到 ...
- [POJ&HDU]杂题记录
POJ2152 树形dp,每次先dfs一遍求出距离再枚举所有点转移即可. #include<iostream> #include<cstdio> #include<cma ...
- poj 1269 水题
题目链接:http://poj.org/problem?id=1269 #include<cstdio> #include<cstring> #include<cmath ...
- 数学之欧拉函数 &几道poj欧拉题
欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...
- POJ 1021 2D-Nim
Description The 2D-Nim board game is played on a grid, with pieces on the grid points. On each move, ...
随机推荐
- 【POJ 2442】 Sequence
[题目链接] http://poj.org/problem?id=2442 [算法] 堆 [代码] #include <algorithm> #include <bitset> ...
- 【POJ 2449】 Remmarguts' Date
[题目链接] http://poj.org/problem?id=2449 [算法] A*(启发式搜索) 首先,求第k短路可以用优先队列BFS实现,当T第k次入队时,就求得了第k短路,但是,这种做法的 ...
- 【POJ 3635】 Full Tank
[题目链接] http://poj.org/problem?id=3635 [算法] 优先队列BFS 实现类似于堆优化dijkstra [代码] #include <algorithm> ...
- Java常用类及反射,类加载
1.系统相关类 Java提供了System类和Runtime类来与程序运行的平台进行交互 A.System类代表当前Java程序的运行平台 a. System类是一个final类,该类的所有属性和方法 ...
- python 46 盒模型 与盒模型布局
一:盒模型 1. 盒模型的概念 广义盒模型:文档中所有功能性及内容性标签,及文档中显示性标签 侠义盒模型:文档中以块级形式存在的标签(块级标签拥有盒模型100%特性且最常用) 盒模型组成:margi ...
- python 46 边界圆角 、a_img_list标签 、伪类选择器
一:边界圆角 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...
- POJ 1946 DP
折腾了一晚上 明天再写.. 2016.5.17 23:59 -> -> #include <cstdio> #include <cstring> #include ...
- informix 通过ADO或ODBC连接提取数据时出现中文乱码的解决方法
最近在做一个项目,是对INFORMIX数据库的数据进行大数据分析,INFORMIX数据库数据有上亿条,没有linux的Root权限和informix数据的生产权限,只能读取.客户要求结果显示在内网wi ...
- 浅谈Java三大框架与应用
前言:对于一个程序员来说,尤其是在java web端开发的程序员,三大框架:Struts+Hibernate+Spring是必须要掌握熟透的,因此,下面谈谈java三大框架的基本概念和原理. JAVA ...
- 图像局部显著性—点特征(FREAK)
参考文章:Freak特征提取算法 圆形区域分割 一.Brisk特征的计算过程(参考对比): 1.建立尺度空间:产生8层Octive层. 2.特征点检测:对这8张图进行FAST9-16角点检测,得到具 ...