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, ...
随机推荐
- Necklace of Beads(polya定理)
http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...
- bzoj 1468 Tree(点分治模板)
1468: Tree Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1527 Solved: 818[Submit][Status][Discuss] ...
- html body中的标签2
一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...
- A - Team
Problem description One day three best friends Petya, Vasya and Tonya decided to form a team and tak ...
- Web Api跨域登录问题
最近项目第一次尝试使用web api,照搬了一般mvc的Forms登录方式,在和前端对接的时候出现一个问题: 前端使用ajax调用登录接口完成登录后,再调用别的接口,被判断为未登录. 如果直接在浏览器 ...
- Ionic3 环境搭建以及基础配置实现(更新中)
GitHub:https://github.com/Teloi 环境配置输入以下命令安装 Ionic (如果刚才设置了淘宝镜像源,可以使用 cnpm 代替 npm):npm install -g io ...
- AndroidStudio怎样导入library项目库
先打开一个Project,然后将libraryr的项目作为module进行导入: File菜单->import module菜单 以上只是导入进来,还没有作为与project真正有效的一部分.需 ...
- 去除DialogFragment的背景阴影,背景色,标题栏
style中: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <s ...
- 【sqli-labs】 less29 GET- Error based -Impidence mismatch -Having a WAF in front of web application (GET型基于错误的带有WAF注入)
这关有点意思,有一点需要事先注意,这关玩的是login.php而不是默认的index.php 再注入之前需要先了解一下HPP(HTTP Parameter Pollution),详情参照这篇 http ...
- mvc自定义控件
//自定义一个DatePicker.cshtml文件@helper Init() { <link href="~/Content/mobiscroll.custom-2.5.0.min ...