夜空中最亮的星

题意:给出两个点在两个坐标系中的坐标,求两个坐标系的夹角。

思路:只要求出一这两个点为向量在两个坐标系(即两个向量的夹角)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

const double PI = 3.14159265358;

struct node
{
    double x,y,w;
}a[1005];

bool cmp(node b1,node b2)
{
    return b1.w < b2.w;
}

double fin(double x1,double y1,double x2,double y2)//求向量夹角
{
    double t=(x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2));
    double ret = acos(t);
    return ret*180/PI;
}

int main()
{
    int T,n,i;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(i = 0; i < n; i++)
        scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].w);
        sort(a,a+n,cmp);
        double x1,x2,y1,y2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        x1 = x2 - x1;
        y1 = y2 - y1;
        x2 = a[1].x - a[0].x;
        y2 = a[1].y - a[0].y;
        printf("%.3lf\n",fin(x1,y1,x2,y2));
    }
    return 0;
}


下面是一个简单的使用Arduino编写的蜂鸣器演奏“夜空最亮”的代码: ``` int speakerPin = 8; // 蜂鸣器引脚 int melody[] = { // 演奏的音符 262, 262, 392, 392, 440, 440, 392, 349, 349, 330, 330, 294, 294, 262, 392, 392, 349, 349, 330, 330, 294, 392, 392, 349, 349, 330, 330, 294, 262, 262, 392, 392, 440, 440, 392, 349, 349, 330, 330, 294, 294, 262 }; int noteDurations[] = { // 音符持续时间 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2 }; void setup() { pinMode(speakerPin, OUTPUT); // 将蜂鸣器引脚设置为输出 } void loop() { for (int i = 0; i < sizeof(melody) / sizeof(melody[0]); i++) { int duration = 1000 / noteDurations[i]; // 计算音符持续时间 tone(speakerPin, melody[i], duration); // 播放音符 delay(duration * 1.3); // 等待一段时间后停止播放 noTone(speakerPin); // 停止播放 } } ``` 在这个代码,我们定义了一个蜂鸣器引脚和一个包含所有演奏音符的数组和一个包含每个音符持续时间的数组。在`setup()`函数,我们将蜂鸣器引脚设置为输出。在`loop()`函数,我们使用`for`循环逐个演奏音符。我们使用`tone()`函数播放每个音符,并使用`delay()`函数等待一段时间后停止播放。最后,我们使用`noTone()`函数停止播放。 请注意,这只是一个简单的示例代码,您可以根据自己的需要进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值