报告见代码。。

 #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 人品题的更多相关文章

  1. POJ推荐50题

    此文来自北京邮电大学ACM-ICPC集训队 此50题在本博客均有代码,可以在左侧的搜索框中搜索题号查看代码. 以下是原文: POJ推荐50题1.标记“难”和“稍难”的题目可以看看,思考一下,不做要求, ...

  2. 最短路+线段交 POJ 1556 好题

    // 最短路+线段交 POJ 1556 好题 // 题意:从(0,5)到(10,5)的最短距离,中间有n堵墙,每堵上有两扇门可以通过 // 思路:先存图.直接n^2来暴力,不好写.分成三部分,起点 终 ...

  3. (转)poj算法做题顺序

    初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj329 ...

  4. poj 1742(好题,楼天城男人八题,混合背包)

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 33269   Accepted: 11295 Descripti ...

  5. poj万人题

    poj提交数量过万的题,除了水爆了的题就是无比经典的,不得不刷的题. 准备将poj上提交次数过万的题刷个遍. 持续更新中... poj 2828(线段树) 此题乃是Zhu, Zeyuan神牛出的,拿到 ...

  6. [POJ&HDU]杂题记录

    POJ2152 树形dp,每次先dfs一遍求出距离再枚举所有点转移即可. #include<iostream> #include<cstdio> #include<cma ...

  7. poj 1269 水题

    题目链接:http://poj.org/problem?id=1269 #include<cstdio> #include<cstring> #include<cmath ...

  8. 数学之欧拉函数 &几道poj欧拉题

    欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...

  9. POJ 1021 2D-Nim

    Description The 2D-Nim board game is played on a grid, with pieces on the grid points. On each move, ...

随机推荐

  1. 【CTSC 2007】 数据备份

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1150 [算法] 首先,有一个很显然的结论 : 如果要使距离和最小,必须选择相邻的办公 ...

  2. 完美解决 linux sublime 中文无法输入

    感谢oschina 中几位前辈的分享 下面是我结合自己的情况所配置的具体步骤: 系统环境: ubuntu 12.10 输入法:fcitx fcitx 安装 apt-get install fcitx ...

  3. angular2之pdf文件操作大全

    最近的项目中需要显示pdf内容.下载pdf.甚至是前端生成pdf 适用于angular2.4或者更高版本 情景1.需要将页面的某个部分转成pdf文件并下载(即将页面的部分html内容转成pdf文件) ...

  4. Django day06 模版层(二) 过滤器 标签

    一: 模板语言之过滤器: " | " 前后的区分: 前面的是函数的第一个参数, 后面的是python的一个函数, 冒号后面的是第二个参数例:  <p>过滤器之默认值:{ ...

  5. Spring-Boot配置文件数据源配置项

    Spring-Boot配置文件数据源配置项(常用配置项为红色) 参数 介绍 spring.datasource.continue-on-error = false 初始化数据库时发生错误时,请勿停止 ...

  6. protobuf 编译 java js文件详解

    首先下载protobuf.exe 下载地址:https://download.csdn.net/download/qq_34756156/10220137 MessageBody.proto synt ...

  7. 【转】Postman接口测试之POST、GET请求方法

    转自竹小冉: https://www.cnblogs.com/zhuxr/p/9009708.html 一.基础知识 1.HTTP的五种请求方法:GET, POST ,HEAD,OPTIONS, PU ...

  8. Android Studio Library 编译成 jar,aar

    1. 导入Library ,打开Library 的build gradle  在最外面添加如下: /** AVLView 自定义的jar 包名 **/ task clearJar(type: Dele ...

  9. Leetcode0100--Same Tree 相同树

    [转载请注明]http://www.cnblogs.com/igoslly/p/8707664.html 来看一下题目: Given two binary trees, write a functio ...

  10. OpenCV : 基于切线方向的边缘增强算法

    使用切线方法,对切线方向上的边缘进行强化: 参考连接:图像锐化和边缘检测 代码: //在种子点方向上寻找合适的梯度,用于寻找边缘 //对low_Gray, high_gray之间的点寻找边缘 void ...