L1-076降价提醒机器人(10分)

C++语言 2021天梯赛L1-4

L1-076 降价提醒机器人 (10 分)

小 T 想买一个玩具很久了,但价格有些高,他打算等便宜些再买。但天天盯着购物网站很麻烦,请你帮小 T 写一个降价提醒机器人,当玩具的当前价格比他设定的价格便宜时发出提醒。

输入格式:
输入第一行是两个正整数 N 和 M (1≤N≤100,0≤M≤1000),表示有 N 条价格记录,小 T 设置的价格为 M。

接下来 N 行,每行有一个实数 Pi(−1000.0<Pi<1000.0),表示一条价格记录。

输出格式:
对每一条比设定价格 M 便宜的价格记录 P,在一行中输出 On Sale! P,其中 P 输出到小数点后 1 位。

作者 DAI, Longao
单位 杭州百腾教育科技有限公司
代码长度限制 16 KB Java (javac) 时间限制 600 ms
内存限制 64 MB
其他编译器 时间限制 400 ms 内存限制 64 MB

输入样例:

4 99
98.0
97.0
100.2
98.9

输出样例:

On Sale! 98.0
On Sale! 97.0
On Sale! 98.9

#include<bits/stdc++.h>
using namespace std;
int main(){
 int a,b,i;
  double c[100];
    cin>>a>>b;
    
    for(i=0;i<a;i++)
        cin>>c[i];
        
   for(i=0;i<a;i++)
   {
       if(c[i]<b)
           printf("On Sale! %.1lf\n",c[i]);//注意%.1lf,考试时没有.1就一直错,但是不知道错哪里,最后得1分
   }
    return 0;
}

在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个6-UHU结构并联机器人正解的MATLAB代码示例: ```matlab % 机器人结构参数 L1 = 10; L2 = 15; L3 = 20; L4 = 18; L5 = 8; L6 = 6; % 末端执行器的位置和姿态 px = 30; py = 20; pz = 15; rx = pi/4; ry = pi/6; rz = pi/3; % 求解关节角度 theta1 = atan2(py, px); theta2 = atan2(pz - L1, sqrt(px^2 + py^2) - L6); theta3 = acos((L2^2 + (sqrt(px^2 + py^2) - L6)^2 + (pz - L1)^2 - L3^2 - L4^2) / (2 * L3 * L4)); theta4 = atan2(pz - L1 - L4 * sin(theta3), sqrt(px^2 + py^2) - L6 - L4 * cos(theta3)); theta5 = atan2(sin(theta4) * (cos(theta1) * cos(rx) * cos(ry) + sin(theta1) * sin(ry)) + cos(theta4) * (cos(theta1) * cos(rz) * sin(ry) - sin(theta1) * cos(rz) * cos(rx)), cos(theta4) * (cos(theta1) * cos(rx) * cos(ry) + sin(theta1) * sin(ry)) - sin(theta4) * (cos(theta1) * cos(rz) * sin(ry) - sin(theta1) * cos(rz) * cos(rx))); theta6 = atan2(cos(theta5) * (cos(theta1) * cos(rx) * cos(ry) + sin(theta1) * sin(ry)) - sin(theta5) * (cos(theta1) * cos(rz) * sin(ry) - sin(theta1) * cos(rz) * cos(rx)), cos(theta5) * (cos(theta1) * cos(rz) * cos(ry) + sin(theta1) * cos(rz) * cos(rx)) + sin(theta5) * (cos(theta1) * sin(rx))); % 各变换矩阵 T01 = [cos(theta1) 0 sin(theta1) 0; sin(theta1) 0 -cos(theta1) 0; 0 1 0 L1; 0 0 0 1]; T12 = [cos(theta2) -sin(theta2) 0 L6 * cos(theta2); sin(theta2) cos(theta2) 0 L6 * sin(theta2); 0 0 1 0; 0 0 0 1]; T23 = [cos(theta3) -sin(theta3) 0 L4 * cos(theta3); sin(theta3) cos(theta3) 0 L4 * sin(theta3); 0 0 1 L2; 0 0 0 1]; T34 = [cos(theta4) -sin(theta4) 0 0; 0 0 -1 -(pz - L1 - L4 * sin(theta3)); sin(theta4) cos(theta4) 0 L3 + L6 + L4 * cos(theta3); 0 0 0 1]; T45 = [cos(theta5) -sin(theta5) 0 0; sin(theta5) cos(theta5) 0 0; 0 0 1 L5; 0 0 0 1]; T56 = [cos(theta6) -sin(theta6) 0 0; 0 0 -1 0; sin(theta6) cos(theta6) 0 0; 0 0 0 1]; % 正解 T06 = T01 * T12 * T23 * T34 * T45 * T56; % 输出结果 disp(['末端执行器位置:(', num2str(px), ', ', num2str(py), ', ', num2str(pz), ')']); disp(['末端执行器姿态:(', num2str(rx), ', ', num2str(ry), ', ', num2str(rz), ')']); disp(['关节角度:(', num2str(theta1), ', ', num2str(theta2), ', ', num2str(theta3), ', ', num2str(theta4), ', ', num2str(theta5), ', ', num2str(theta6), ')']); ``` 需要根据具体机器人的结构和参数、末端执行器的位置和姿态来修改代码中的参数,以得到正确的结果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多练项目

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值