UVA 10881 Piotr's Ants

保姆级教程:从OrthoFinder到CAFE5,手把手搞定基因家族收缩扩张分析(附完整代码与避坑指南) 本文提供从OrthoFinder到CAFE5的基因家族收缩扩张分析全流程教程,涵盖数据预处理、系统发育树准备、CAFE5运行与参数优化等关键步骤。通过详细代码示例和避坑指南,帮助研究者高效完成基因家族进化分析,特别适合生物信息学初学者。 阅读详情

Piotr's Ants

Piotr likes playing with ants. He has n of them on a horizontal poleL cm long. Each ant is facing either left or right and walks at a constant speed of 1 cm/s. When two ants bump into each other, they both turn around (instantaneously) and start walking in opposite directions. Piotr knows where each of the ants starts and which direction it is facing and wants to calculate where the ants will end upT seconds from now.

Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing 3 integers:L ,T andn (0 <= n <= 10000). The nextn lines give the locations of then ants (measured in cm from the left end of the pole) and the direction they are facing (L or R).

Output
For each test case, output one line containing "Case #x:" followed byn lines describing the locations and directions of then ants in the same format and order as in the input. If two or more ants are at the same location, print "Turning" instead of "L" or "R" for their direction. If an ant falls off the polebeforeT seconds, print "Fell off" for that ant. Print an empty line after each test case.


Sample InputSample Output
2
10 1 4
1 R
5 R
3 L
10 R
10 2 3
4 R
5 L
8 R
Case #1:
2 Turning
6 R
2 Turning
Fell off

Case #2:
3 L
6 R
10 R


【思路分析】

   一个花了好几天都没有思路的问题。。。题意是在一个木棍上有若干个蚂蚁,它们会往左或者往右每秒移动一个单位,当两只蚂蚁相撞时,立即发生“弹性碰撞”,求在时刻T时每一只蚂蚁的状态。没有思路的原因是无法将其抽象为一个具体的模型。最后在大白书上看到“两只蚂蚁相撞时视为对穿而过”便迎刃而解了,即忽视每一步的具体细节,每一个蚂蚁的相对顺序是保持不变的,只需考虑初态和终态,最后根据其移动的距离判断其位置。除此之外,还需要记录每一个蚂蚁的初始位置,以便按序输出结果。


代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
int L,T,n;
struct Ant
{
    int index;
    int pos;
    int dir;
    Ant(){}
    Ant(int i,int p,int d) : index(i),pos(p),dir(d){}
    bool operator < (const Ant& a) const
    {
        return pos < a.pos;
    }
}before[maxn],last[maxn];
int order[maxn];
char dirName[3][10] = {"L","Turning","R"};

void init()
{
    scanf("%d %d %d",&L,&T,&n);
    for(int i = 0;i < n;i++)
    {
        int pos,dir;
        char c;
        scanf("%d %c",&pos,&c);
        dir = c == 'L' ? -1 : 1;
        before[i] = Ant(i,pos,dir);
        last[i] = Ant(0,pos + T * dir,dir);
        //相撞时视为相穿而过,暂时不计算顺序、不改变方向
    }
}
void solve(int t)
{
     printf("Case #%d:\n",t);
     sort(before,before + n);
     for(int i = 0;i < n;i++)
     {
         order[before[i].index] = i;
     }
     sort(last,last + n);
     for(int i = 0;i < n - 1;i++)
     {
         if(last[i].pos == last[i + 1].pos)//判断T时刻是否有位置相同的,即相撞时的情况
         {
             last[i].dir = last[i + 1].dir = 0;
         }
     }
     for(int i = 0;i < n;i++)
     {
         int temp = order[i];
         if(last[temp].pos < 0 || last[temp].pos > L)
            printf("Fell off\n");
         else
         {
             printf("%d %s\n",last[temp].pos,dirName[last[temp].dir + 1]);
         }
     }
     printf("\n");
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i = 1;i <= t;i++)
    {
       init();
       solve(i);

    }
    return 0;
}




Jacobi正交多项式在数值分析中的应用与实现 本文深入探讨了Jacobi正交多项式在数值分析中的核心应用与实现。作为最通用的正交多项式族,Jacobi多项式通过参数α和β的调节,可退化为切比雪夫、勒让德等经典多项式,为函数逼近、奇异积分和微分方程求解提供了统一框架。文章重点解析了其在加权高斯积分(高斯-雅可比积分)和谱方法求解微分方程中的关键作用,并提供了基于递归关系和SciPy的稳定高效实现方案,帮助读者掌握这一强大的数值计算工具。 阅读详情

相关推荐

金蝶云星空-协同开发云-安装开发环境

金蝶协同开发云就是不需要每一个开发都在自己的本机安装开发环境,自己安装可容易出错,包括源代码管理也一并解决了,大大减少了开发人员的工作量和降低了上手的难度。

qq_33881408的博客 5615

uva 10881 - Piotr's Ants(排序)

题目链接:10881 - Piotr's Ants 题目大意:在一个长为L的木棒上有n只蚂蚁,给出蚂蚁的初始位置以及方向,问说移动T秒后各个蚂蚁的位置以及状态,如果两只蚂蚁在移动的过程中相撞,则会同时掉头。 解题思路:问题只要解决说两只蚂蚁相撞的情况就差不多了,其实从整体上来看(不考虑蚂蚁的编号),“相撞”和对穿而过“是一样的,只不过移动到那个位置的蚂蚁并不是先前的那只。所以说

不慌不忙、不急不躁 1375

影刀RPA进阶:Excel多条件筛选与数据提取实战

本文详细介绍了如何利用影刀RPA实现Excel多条件筛选与数据提取的自动化。通过拆解文本、数值、日期及颜色筛选等核心指令,并结合实战案例,指导用户构建稳健的销售数据提取机器人,从而高效处理复杂数据报表,提升工作效率。

onion的博客 543

Piotr's Ants UVA - 10881 (我的天,晚安晚安~~)

#include <iostream> #include<stdio.h> #include<algorithm> #include<map> using namespace std; const int maxn=10009; struct st { int id; int x; int i; } a[maxn]...

chen_zan_yu_的博客 210

调试GMS应用,报错“此设备未获得play保护机制认证”问题解决

不少同学在调试GMS相关应用时,需登录Google账号,有时会弹出如下通知。Google登录界面也会出现如下提示这个报错的原因是设备未通过Google认证,google服务器未配置荣耀设备的型号白名单导致国内网页有一些指导方法在鸿蒙\荣耀的设备上消除这个提示,但本质的问题没有解决,无法登录Google账号。

胡同老道的博客 2万+

用 Python 和 uiautomation 实现微信批量发送

思路是这样,将要发送的人员名单(包括称呼)以及发送内容都维护到Excel里,程序运行时读取Excel里内容,自动搜索人员姓名(微信昵称或备注名),填入要发送的内容,拼接上称呼(如果需要的话)自动点击发送,这样轮巡直至名单人员全部发送完成。、

jankingdom的专栏 1476

【UVa10881 Piotr's Ants】数学 | 思维 | STL | E

近来感觉脑袋有点抽,做几道思维题活动活动… 【UVa10881】Piotr’s Ants Time limit: 3.000 seconds Tags:数学 思维 题目描述 给定一根长为 L&nbsp;cmL\ cmL&nbsp;cm 的木棍和 nnn 只蚂蚁在初始时刻距木棍左端点的距离以及初始朝向(LLL 表示向左,RRR 表示向右) 蚂蚁运动速度为 1&nbsp;cm/s1\ cm/s1...

Keyu Tian's blog 225

如何点亮一颗sensor

要点亮一个sensor需要从,时钟、sensorI2C,供电,reset脚,mipi的配置几个方面一一确认。 reset脚拉高 给sensor的时钟有没有。(目前用到的常为24MHZ) 供电 查看sensor的数据手册,看有几个电源,用示波器量一下是否为手册规定的电压 比如:DVDD 数字电压: AVDD模拟电压 DOVDD芯片引脚出来的电压等为多少。 sensor的I2C能否抓到 将I2C的口对应上,用示波器量取i2c的波形。 检查有应答并且数据正确。读写地址是否正...

weixin_40787463的博客 3661

UVa 10881 Piotr's Ants (排序)

UVa 10881 Piotr’s Ants题目大意:在L长的木棍上有n只蚂蚁,向左或右爬,速度为1单位长度每秒,若两蚂蚁撞上,则掉头,求T秒以后各蚂蚁所在位置,若掉下去,输出”Fell off”,否则输出位置和朝向,若此时正撞上,朝向输出”Turning”.题目分析:这道题还是有一些思维含量的.实际上,n只蚂蚁在爬行过程中,其相对位置(也就是第几号位置)是不会改变的,所以可以不考虑对撞之后换方向的

Continue 482

《python神经网络编程》程序实现

《python神经网络编程》程序实现 通过对这本书的学习,结合这本书的内容: 完成了以下代码: 其中NN.py实现了一个类,这个类可以完成神经网络的初始化,训练以及输入数据并得出结果。 而run.py则是对神经网络类的使用 NN.py: import numpy import scipy.special #神经网络类的实现 class neuralNetwork: #构造函数初始化类 def __init__(self,inputnodes,hiddennodes,outputnodes

ms8617484的博客 623

Mathematica 训练课(12)常用注释方法

Mathematica从入门到进阶

qq_25018077的博客 9078

UVA - 10881 Piotr's Ants 推理

题目大意:有n只蚂蚁在一根长度为L的木棍上,这n只蚂蚁有的向左移动有的向右移动,如果两只蚂蚁相碰的话,这两只蚂蚁就会按相反方向继续前进,每只蚂蚁的移动速度为1m/s,问T秒后每只蚂蚁的状态和所在的位置 解题思路:按从木棒的从左到右排序,T秒后,每只蚂蚁在木棒上的从左到右的位置是不变,这样的话,就可以确定每只蚂蚁最终位置,因为相碰的话,就会按反方向运动,这样的话就相当于两只蚂蚁交换移动,剩下的移动

静静地码 680

YOLOv8改进 | 融合篇,YOLOv8改进主干网络为MobileNetV4+CBAM注意机制+Powerful-IoU损失函数(2024 最新IOU),全网首发,实现极限涨点

本文将在 YOLOv8 主干中引入 MobileNetV4 轻量化骨干,同时,在检测头引入 CBAM机制注意力机制,并采用 Powerful-IoU 损失函数作为模型的损失函数,其中,MobileNetV4 通过引入通用反向瓶颈(UIB)搜索块和 Mobie MQA 注意力模块创新设计,实现了模型的轻量级化;同时,MobileNetV4 采用了优化的 NAS 策略,通过粗粒度和细粒度搜索相结合的方法,显著提高了搜索效率并改善了模型质量。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 3806

UVa10881 Piotr's Ants【模拟】

“One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords.” Kent Brockman  Piotr likes playing with ants. He has n of them

海岛Blog 1433

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

uva 10881 Piotr's Ants (模拟)

uva 10881 Piotr's Ants "One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords."Kent Brockman Piotr likes playing wit

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 1113

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

UVA 10881 [Piotr's Ants]

UVA 10881 [Piotr’s Ants]index UVA 10881 Piotrs Ants index Description input output code DescriptionPiotr likes playing with ants. He has n of them on a horizontal pole L cm long. Each ant is facing

arbietrsc的博客 359

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

思维题 UVA 10881 Piotr's Ants

题目传送门 1 /* 2 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 3 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 4 关键2:蚂蚁的相对位置不变 关键3:order数组记录顺序 5 */ 6 #include <cstdio> ...

weixin_30511107的博客 65

UVA.10881 Piotr's Ants (思维题)

UVA.10881 Piotr’s Ants (思维题)题意分析有一根长度为L cm的木棍,上有n只蚂蚁,蚂蚁要么向左爬,要么向右,速度均为1cm/s,若2只蚂蚁相撞,则蚂蚁同时调头。求解第T秒时这n只蚂蚁的状态。 若此时相撞 输出:Turning 若此时已经掉下木棍 输出:Fell off 且要按照输入时的顺序输出各个蚂蚁的状态此题难点有2个: 1.其实相撞可以理解为交叉走过(因为速度相同

Pengwill's Blog 393

uva10881 Piotr's Ants

分析

YHaX的博客 267

UVa 10881Piotr's Ants【思维】

题目链接 对于每个蚂蚁来说,他相对于其他蚂蚁的位置是固定的,赶超前面或者被后面的赶超都是要回头的,所以,假设木棒无限长,位于第一位的永远在第一位,第二位的永远在第二位。同时每两个碰头的蚂蚁其实就是类似于交换了身份继续前进。所以,先不管他们的碰头,就让每个沿着路线继续走下去。由前面的可以知道,每个蚂蚁的最终状态的位置排列的顺序就是一开始蚂蚁的编号。 #include #include #in

博客已搬迁到http://www.cnblogs.com/cniwoq/ 517

Piotr's ants UVA 10881

Problem D Piotr's Ants Time Limit: 2 seconds   "One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords."

Jackwuyongxing的专栏 609

cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁

1456. [UVa 10881,Piotr's Ants]蚂蚁 ★ 输入文件:Ants.in 输出文件:Ants.out简单对比时间限制:1 s 内存限制:128 MB 【题目描述】 一根长度为L厘米的木棍上有n只蚂蚁,每只蚂蚁要么往左爬要么往右爬,速度为1cm/s。当两只蚂蚁相遇时,二者同时掉头(掉头时间忽略不计)。给出每只蚂蚁的初始位置和朝向,计算T秒之后蚂...

weixin_30448603的博客 86

Piotr's Ants(Uva 10881)

“One thing is for certain: there is no stopping them; the ants will soon be here. And I, for one, welcome our new insect overlords.” —–Kent Brockman Problem Description Piotr likes playing with an

ここはHudsonJoeのブログです,いらっしゃいませ 683

UVA10881 Piotr's Ants

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=1822&mosmsg=Submission+received+with+ID+12182780 题目大意:一根长度为L的木棍上,有n只蚂蚁,每只蚂蚁要么向左爬要么向右爬,速度为

yxr941225的专栏 680
上一篇: HDU 5441 Travel (带权并查集 + 离线操作)
下一篇: HDU 1207 汉诺塔II(递推)
Spectacules
博客等级 码龄12年 2粉丝 69原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值