报告见代码。。

 #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. B1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 数学

    今天净做水题了,这个题还不到十五分钟就搞定了,思路特别简单,就是直接按照线性求因子个数的思路就行了. 题干: Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜 ...

  2. 杂项-Java:自定义标签

    ylbtech-杂项-Java:自定义标签 1.返回顶部 1. 一般我们说自定义标签是指JSP自定义标签.自定义标签在功能上逻辑上与javaBean 类似,都封装Java 代码.自定义标签是可重用的组 ...

  3. succ

  4. 在使用实体框架(Entity Framework)的应用中加入审计信息(Audit trail)跟踪数据的变动

    在一些比较重要的业务系统中,通常会要求系统跟踪数据记录的变动情况.系统要记录什么时间,什么人,对那些信息进行了变动. 比较简单的实现方式是在每个表中加入两个字段CreatedBy和CreatedAt, ...

  5. C#方法的练习

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo ...

  6. C# 多线程系列(四)

    Parallel类 Parallel类定义了for.foreach和invoke的静态方法.Parallel类使用多个任务,因此使用多个线程来完成这个作业. Parallel.For Parallel ...

  7. 安卓桌布显示的dip和px

    安卓程序设计界面显示设置图像大小,在layout.xml里面有dip和px选项,dip为 什么 暂时还不知道,或许是设计桌布的设定像素比率,px为像素值: 比如我的手机是 Lenovo K920,屏幕 ...

  8. 【汇编】MASM6.15几个简单的汇编程序

    /***************通过调用(INT 21H)表中的01h号功能号从键盘输入一个字符并回显到视频显示器上*****************/ DATAS SEGMENT ;此处输入数据段代 ...

  9. 【sqli-labs】 less10 GET - Blind - Time based. - Double quotes (基于时间的双引号盲注)

    这个和less9一样,单引号改完双引号就行了 http://localhost/sqli/Less-10/?id=1" and sleep(5)%23 5s后页面完成刷新 http://lo ...

  10. sql server time(7) 默认值

    语句为 ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_TimeDefault DEFAULT '00:00:00' FOR YourTimeColumn 比如 ...