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

  方法:用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. WTL版本ACEdit控件,改写自MFC版,附带源码

    自动完成是个很酷也很实用的功能,比如在浏览器地址栏输入几个字母,相关的记录就会在下拉框中陈列出来. 最近在做公司产品UI部分的改善,原版本是MFC做的,我决定用WTL,于是就遇到自动完成控件的问题.遍 ...

  2. 大数据除法(Large data division)

    题目描述 Description 除法是计算中的基础运算,虽然规则简单,但是位数太多了,也难免会出错.现在的问题是:给定任意位数(足够大就可以啦O(∩_∩)O)的一个被除数,再给定一个long lon ...

  3. C# 验证码生成(MVC和非MVC两种方式)

    /// <summary> /// 生成验证码 /// </summary> /// <param name="length">指定验证码的长度 ...

  4. keepalived问题

    Sep 30 11:41:34 XSXSH-LB2 Keepalived[2735]: Starting Keepalived v1.2.12 (04/08,2014) Sep 30 11:41:34 ...

  5. eclipse设置java虚拟机内存大小

    设置java虚拟机大小可以让eclipse启动运行更快...... 在eclipse中点击window--preferences--java--Installed JREs. 然后看右边的框,鼠标点击 ...

  6. 华中农业大学新生赛C题

    http://acm.hzau.edu.cn/problem.php?id=1099 题意: 输入两个整数 l 和 n,代表半径和output的保留小数点位数. 输出圆的面积,保留n位小数. 一开始觉 ...

  7. shell脚本调试方法

    我们开启了 Shell 脚本调试系列文章,先是解释了不同的调试选项,下面介绍如何启用 Shell 调试模式. 写完脚本后,建议在运行脚本之前先检查脚本中的语法,而不是查看它们的输出以确认它们是否正常工 ...

  8. 新学的js精集

    逻辑运算符比较 逻辑与和逻辑或这两个逻辑运算符它不单单会输出布尔型数据 1.只要"||"前面为false,无论"||"后面是true还是false,结果都返回& ...

  9. VBS常用使用技巧

    (一)VBS常用函数使用笔记: 1.Msgbox语法:msgbox "对话框内容", , "对话框的标题" 2.inputbox是VBS内建的函数,可以接受输入 ...

  10. allocator 类

    allcator是一个模板类 定义在memory头文件中,将内存分配与对象构造分开,分配的内存是原始的.未构造的 一.how to use 因其实一个类,则使用allcator时需要首先声明一个类对象 ...