UVALive 2517 Moving Object Recognition(模拟)

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

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

  代码:

#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 550
int n,m,go[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int vis[N][N],Max;
char maps[N][N],op[N];
double X[N*1000],Y[N*1000];
struct Pos
{
    int x,y;
};
bool in_maps(int x,int y)
{
    return (x>=1 && x <= n && y>=1 && 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 = 0;
    vis[sx][sy] = 1;
    while(!que.empty())
    {
        now = que.front();
        que.pop();
        tot++;
        for(int i = 0; i < 4; i++)
        {
            nxt.x = now.x + go[i][0];
            nxt.y = now.y + go[i][1];
            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] = 1;
            }
        }
    }
    return tot;
}
void get_Max()
{
    int nxtx,nxty,tmp,startx,starty;
    Max = -99999999;
    memset(vis,0,sizeof(vis));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; 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,0,sizeof(vis));
    bfs(startx,starty);
}
void get_xy(int k)
{
    double sumx = 0,sumy = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; 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==0) break;
        T = 0;
        while(1)
        {
            for(int i = 1; i <= n; i++)
            {
                scanf("%s",maps[i]+1);
            }
            scanf("%s",op);
            get_Max();
            get_xy(T);
            T++;
            if(op[0]==‘=‘) break;
        }
        //printf("T = %d\n",T);
        T /= 2;
        ansx = ansy = 0.0;
        for(int i = 0; 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 0;
}
时间: 2024-08-29 17:47:10

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

【Paper Reading】Object Recognition from Scale-Invariant Features

Paper: Object Recognition from Scale-Invariant Features Sorce: http://www.cs.ubc.ca/~lowe/papers/iccv99.pdf SIFT 即Scale Invariant Feature Transfrom, 尺度不变变换,由David Lowe提出.是CV最著名也最常用的特征.在图像目标识别的应用中,常常要求图像的特征有很好的roboust即不容易受到平移,旋转,尺度缩放,光照,仿射的英雄.SIFT算子具有

论文笔记之:MULTIPLE OBJECT RECOGNITION WITH VISUAL ATTENTION

 Multiple Object Recognition With Visual Attention Google DeepMind  ICRL 2015 s

论文阅读笔记--Selective Search for Object Recognition

Selective Search for Object Recognition [email protected] 作者: J. R. R. Uijlings, K. E. A. van de Sande, T. Gevers, A. W. M. Smeulders. 引用: Uijlings, Jasper RR, et al. "Selective search for object recognition." International journal of computer v

Selective Search for Object Recognition

http://blog.csdn.net/charwing/article/details/27180421 Selective Search for Object Recognition 是J.R.R. Uijlings发表在2012 IJCV上的一篇文章.主要介绍了选择性搜索(Selective Search)的方法.选择性搜索综合了蛮力搜索(exhaustive search)和分割(segmentation)的方法.选择性搜索意在找出可能的目标位置来进行物体的识别.与传统的单一策略相比,

对这个运动目标检测方法实现的结果A Hybrid Algorithm for Moving Object Detection

最近在做烟火检测,需要用到运动检测,看到论文A System for Video Surveillance and Monitoring中的A Hybrid Algorithm for Moving Object Detection这个方法,我用opencv将其实现,代码下面会贴出,但是其的到的结果很差,不知道代码哪里出了问题,请高手给予指点,谢谢! 左图为原图,有图为用上面论文中的方法得到前景图像,[自己的代码可能写错了,请大神们给予指点谢谢] 代码如下: #include <stdio.h>

UvaLive 6662 The Last Ant 模拟

链接:http://vjudge.net/problem/viewProblem.action?id=49407 题意:有若干只蚂蚁,给出它们在管子内的坐标和它们的移动方向,如果两只蚂蚁在坐标为整数的位置相遇,那么它们分别调头,否则,两只蚂蚁穿过对方,继续前进.现在问什么时候蚂蚁能全部离开这个管子,并且求出最后一只离开管子的蚂蚁的编号. 是一道纯模拟题,以前觉得这种模拟题的代码量太大,不愿意做,这次A掉以后,感觉神清气爽. 思路:直接模拟即可. 代码: #include<iostream> #

uvalive 4254 Processor处理器 (二分模拟+贪心)

 有n个任务,每个任务有ri,di,wi;代表任务的[ri,di]代表可以做这个任务的时间区间,而wi代表这个任务的工作量;现在有有个处理器,如果它的执行速度是s,则完成第i个任务所需时间wi/s;要求算出处理器执行过程中最大速度的最小值 思路很简单二分,但如何模拟是难点,可以模拟处理器每一秒的工作,对于每一秒来说,用优先队列储存当前时间下可以处理的任务,优先处理d小的,如果处理完了,那么处理下一个任务,如果没处理完,时间加一. #include<cstdio> #include<c

UvaLive 4917 Abstract Extract (模拟)

题意: 给定一篇文章, 文章中有段落, 段落中有句子. 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单词只算一个. 题目中关键段: A topic sentence for a paragraph is the single sentence in the paragraph that best describes the paragraph's content. For our purposes,

UVAlive 6693 Flow Game(模拟)

题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4705 思路:若有解,两点连线最小距离=曼哈顿距离+1,则ans=abs(x1-x2)+abs(y1-y2)+abs(x3-x4)+abs(y3-y4)+2.若无解,则两线相交:对于边界,逆时针遍历,若1212或2121则此时无解,其他情况有解.注意所有点在同一行或同