题目看上去很吓人,很高端,但其实很简单,不要被吓到,照搬题目的公式就可以了。

  方法:用BFS求出最大块和重心,找出题目公式需要的未知量,然后套到题目公式里就可以求出答案了。

  代码:

#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 550
int n,m,go[][] = {{,},{-,},{,},{,-}};
int vis[N][N],Max;
char maps[N][N],op[N];
double X[N*],Y[N*];
struct Pos
{
int x,y;
};
bool in_maps(int x,int y)
{
return (x>= && x <= n && y>= && y<=m);
}
int bfs(int sx,int sy)
{
queue<Pos> que;
while(!que.empty()) que.pop();
Pos now,nxt;
now.x = sx; now.y = sy;
que.push(now);
int tot = ;
vis[sx][sy] = ;
while(!que.empty())
{
now = que.front();
que.pop();
tot++;
for(int i = ; i < ; i++)
{
nxt.x = now.x + go[i][];
nxt.y = now.y + go[i][];
if(in_maps(nxt.x,nxt.y) && !vis[nxt.x][nxt.y] && maps[nxt.x][nxt.y]=='x')
{
que.push(nxt);
vis[nxt.x][nxt.y] = ;
}
}
}
return tot;
}
void get_Max()
{
int nxtx,nxty,tmp,startx,starty;
Max = -;
memset(vis,,sizeof(vis));
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
if(maps[i][j] == 'x' && !vis[i][j])
{
tmp = bfs(i,j);
if(tmp > Max)
{
Max = tmp;
startx = i;
starty = j;
}
}
}
}
// printf("Max = %d\n",Max);
// printf("sx = %d sy = %d\n",startx,starty);
memset(vis,,sizeof(vis));
bfs(startx,starty);
}
void get_xy(int k)
{
double sumx = ,sumy = ;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= m; j++)
{
if(vis[i][j])
{
sumy += (j*1.0);
sumx += (i*1.0);
}
}
}
sumx /= Max;
sumy /= Max;
X[k] = sumx;
Y[k] = sumy;
}
int main()
{
int T;
double ansx,ansy;
while(~scanf("%d%d",&m,&n))
{
if(n+m==) break;
T = ;
while()
{
for(int i = ; i <= n; i++)
{
scanf("%s",maps[i]+);
}
scanf("%s",op);
get_Max();
get_xy(T);
T++;
if(op[]=='=') break;
}
//printf("T = %d\n",T);
T /= ;
ansx = ansy = 0.0;
for(int i = ; i < T; i++)
{
ansx += (X[i+T] - X[i]);
ansy += (Y[i+T] - Y[i]);
}
ansx /= (T*T);
ansy /= (T*T);
printf("%.2lf %.2lf\n",ansy,ansx);
}
return ;
}

UVALive 2517 Moving Object Recognition(模拟)的更多相关文章

  1. 论文阅读之 DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation

    DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation Xia ...

  2. 【Paper Reading】Object Recognition from Scale-Invariant Features

    Paper: Object Recognition from Scale-Invariant Features Sorce: http://www.cs.ubc.ca/~lowe/papers/icc ...

  3. Computer Vision_33_SIFT:Object recognition from local scale-invariant features——1999

    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...

  4. Notes on 'Selective Search For Object Recognition'

    UijlingsIJCV2013, Selective Search For Object Recognition code 算法思想 利用分割算法将图片细分成很多region, 或超像素. 在这个基 ...

  5. 论文笔记之:Multiple Object Recognition With Visual Attention

     Multiple Object Recognition With Visual Attention Google DeepMind  ICRL 2015 本文提出了一种基于 attention 的用 ...

  6. 论文笔记:Selective Search for Object Recognition

    与 Selective Search 初次见面是在著名的物体检测论文 「Rich feature hierarchies for accurate object detection and seman ...

  7. 目标检测--Selective Search for Object Recognition(IJCV, 2013)

    Selective Search for Object Recognition 作者: J. R. R. Uijlings, K. E. A. van de Sande, T. Gevers, A. ...

  8. PASCAL VOC数据集The PASCAL Object Recognition Database Collection

    The PASCAL Object Recognition Database Collection News 04-Apr-07: The VOC2007 challenge development ...

  9. Selective Search for Object Recognition

    http://blog.csdn.net/charwing/article/details/27180421 Selective Search for Object Recognition 是J.R. ...

随机推荐

  1. Visual Studio 2010 安装帮助文档问题

    今天重装系统,装完VS2010后,如往常一样安装文档,却弹出如下错误"Could not create the local store in the specified folder.... ...

  2. Android上的远程调试

    来源: http://www.seejs.com/archives/296 目录 远程调试概述 使用 Chrome 的 ADB 扩展进行远程调试 1. 安装 ADB 扩展 2. 启用你的移动设备上的 ...

  3. ASP.NET中application对象的用法(面试题)

    ASP.NET中application对象的用法 本文导读:Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.Appli ...

  4. A. Brain's Photos ——Codeforces Round #368 (Div. 2)

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. poll机制分析[转]

    所有的系统调用,基于都可以在它的名字前加上"sys_"前缀,这就是它在内核中对应的函数.比如系统调用open.read.write.poll,与之对应的内核函数为:sys_open ...

  6. .net core 系列

    1..net core 验证码 2..net core 导出excel 3..net core 上传文件 4..net core 时间戳转换 5..net core 读取配置文件 6..net cor ...

  7. 用python写刷票程序

    刷票一般要突破以下限制: 1.验证码识别 2.同一ip不可连续投票 解决办法 1.用tesseract工具,链接在此 https://code.google.com/p/tesseract-ocr/  ...

  8. leetcode136 利用异或运算找不同的元素

    Given an array of integers, every element appears twice except for one. Find that single one. Note: ...

  9. Chapter 1 First Sight——30

    The girl sitting there giggled. I'd noticed that his eyes were black — coal black. 那个坐在那里的女孩笑着.我注意到她 ...

  10. LeetCode OJ 297. Serialize and Deserialize Binary Tree

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...