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

  方法:用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. LeetCode OJ 63. Unique Paths II

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  2. LeetCode OJ 34. Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  3. Codeforces Round #256 (Div. 2) B Suffix Structures

    Description Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" t ...

  4. 洛谷-笨小猴-NOIP2008提高组复赛

    题目描述 Description 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设m ...

  5. NOIP2014-普及组复赛-第四题-子矩阵

    题目描述 Description 给出如下定义: 1. 子矩阵:从一个矩阵当中选取某些行和某些列交叉位置所组成的新矩阵(保持行与列的相对顺序)被称为原矩阵的一个子矩阵. 例如,下面左图中选取第2.4行 ...

  6. Openjudge-计算概论(A)-过滤多余的空格

    描述: 一个句子中也许有多个连续空格,过滤掉多余的空格,只留下一个空格. 输入一行,一个字符串(长度不超过200),句子的头和尾都没有空格.输出过滤之后的句子. 样例输入 Hello world.Th ...

  7. SharePoint 2013 InfoPath 无法保存下列表单

    转载自:http://www.cnblogs.com/jianyus/p/3470121.html 在使用InfoPath发布表单,发布到SharePoint服务器报错,如下介绍: 环境:Window ...

  8. Xcode中AutoLayOut的简单使用

    做了一段界面最头疼的就是适配的问题了,使用AutoLayOut做适配是一个不错的选择, 自己做的一个小例子,具体如下: 一.在新建的xib文件中勾选上 autoLayout,默认是勾选上的 二.在xi ...

  9. 9.创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。

    package com.hanqi.test; public class Triangle { private double a,b,c; public Triangle(double d,doubl ...

  10. ajax 假上传文件

    1. <form name="certForm" id="certForm" method="post" action="x ...