poj 2674 Linear world

题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名字。

题解:1.一种计算机编程的普遍思想,就是变化不一定需要体现出来、

      2.这道题就是首先蚂蚁碰撞调头,但是在编程中不一定需要体现出来,碰撞调头可以等效成擦肩而过

      3.还有就是蚂蚁的相对顺序总是固定的,我用的方法就是假设这条线无限长,蚂蚁可以无限制的走下去,然后

找到那个最后出现在边界线的蚂蚁,并通过相对顺序算出他是哪个蚂蚁

总结:不知为何,g++提交就re了c++就过了


<pre name="code" class="cpp">#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 255
#define MAXM 32005
struct Pos
{
    double pos;
    char s[MAXN],dir[4];
    bool operator < (const struct Pos & a)const{
        return pos < a.pos;
    }
}pos[MAXM];
double last[MAXM];
int main()
{
    int n;
    double l,v,len;
    while(scanf("%d",&n),n)
    {
        scanf("%lf%lf",&l,&v);
        double maxn = 0;
        for(int i = 0;i < n;i++)
        {
            scanf("%s %lf %s",&pos[i].dir,&pos[i].pos,&pos[i].s);
            if(pos[i].dir[0] == 'p' || pos[i].dir[0] == 'P')
                len = l - pos[i].pos;
            else len = pos[i].pos;
            maxn = max(maxn,len);
        }
        bool zero = false;
        for(int i = 0;i < n;i++)
        {
            if(pos[i].dir[0] == 'p' || pos[i].dir[0] == 'P')
                last[i] = pos[i].pos + maxn;
            else last[i] = pos[i].pos - maxn;
            if(last[i] == 0)zero = true;
        }
        int ind = 0,limit = l;
        if(zero)limit = 0;
        for(int i = 0;i < n;i++)
        {
            if(last[i] < limit)
                ind++;
        }
        printf("%13.2lf %s\n",(int)(maxn / v * 100) / 100.0,pos[ind].s);
    }
}


 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值