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

  方法:用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. Excel教程(3) - 函数输入方法

    对 Excel 公式而言,函数是其中的主要组成部分,因此公 式输入可以归结为函数输入的问题. "插入函数"对话框 "插入函数"对话框是 Excel 输入公式的重 ...

  2. winform实现矩形框截图

    使用方法如下: private void button1_Click(object sender, EventArgs e) { s.GerScreenFormRectangle(); } priva ...

  3. jquery倒计时过几秒页面跳转 js倒计时

    //银行认证成功跳转 var time=setInterval (showTime, 1000); var second=5; function showTime() { if(second==0) ...

  4. CFNetwork SSLHandshake failed (-9824) ios 9

    设置 NSAppTransportSecurity

  5. OC工程调用Swift方法

    1.建一个OC工程命名为SwiftOC.如图所示: 2.新建一个swfit文件命名为Test.swift,会弹出提示,选择Create Bridging Header建立桥接文件,系统会建立“工程名- ...

  6. Flask -- 使用数据库(Sqlite3)、用户注册、登录注销、修改密码

    # 使用sqlite数据库 import sqlite3from contextlib import closing app.config.update( DATABASE = 'my.db', #相 ...

  7. eclipse 中执行 main 函数如何添加参数

    我们通常执行 main 函数都是直接在类界面 右键 选择 Run As --> Java Application 但是如何 执行时带有参数呢? 右键 --> Run As --> R ...

  8. 调试MVC项目,不关闭 IIS EXPRESS

    在VS主面板打开:工具->选项->调试->编辑继续   取消选中[启用"编辑并继续"] 就OK了 (英文版的请对应相应的操作) 不过这是针对所有的调试,如果你想针 ...

  9. LoadRunner学习知多少--IP欺骗使用

    使用IP欺骗功能时,需要将系统防火墙,杀毒软件关闭(如果有影响的话) 一.为什么要设置IP欺骗 1. 当某个IP的访问过于频繁,或者访问量过大时,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频 ...

  10. CSS3秘笈:第十一章

    表格和表单的格式化 1.表格的各种标签提供了许多有用的“钩子”,可以再上面挂CSS样式.如果创建了<th>标签样式,那么每一个列的标题——<th>标签——看起来就有可能与其他的 ...