SDNU Warming up for Team Selection

本文解析了几道典型的算法题目,包括蚂蚁爬行问题、战棋游戏路径规划、表达式计算等,通过具体案例展示了数学积分的应用、优先队列的使用及变量替换计算的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A - An ant's story

HDU - 3343                    
Long long ago, there is an ant crawling on an L-meter magic rubber band with speed of v cm/s.The magic rubber band will elongate m meters every second. We can assume that the magic rubber band elongates equably. Now, the ant is on the start point and crawling to another point, please tell me whether it can reach the endpoint.

InputThe first line of the input is T, which stands for the number of test cases you need to solve.
Each case include three integers: L , v , m ( 0< L< 10^9,0<= v, m< 10^ 9,).OutputFor each test case, if the ant can reach endpoint, output "YES", otherwise "NO".Sample Input
1
99999 61 1
Sample Output
YES

这道题有点坑这么简单竟然做了两个多小时。
这道题就是考数学的积分
晕死,这是一道 数学题

蚂蚁速度v cm/s,蝇长L;每秒蝇长增m;
第一秒: 蚂蚁走了蝇长的0.01*v/(L+m);
第二秒: 蚂蚁走了蝇长的0.01*v/(L+2*m);
第三秒:蚂蚁走了蝇长的0.01*v/(L+3*m);
第四秒:蚂蚁走了蝇长的0.01*v/(L+4*m);
第t秒:蚂蚁走了蝇长的0.01*v/(L+t*m);
把以上结果加起来,求积分,∫0.01*v/(L+t*m)dt=0.01*(v/m)*ln(L+t*m)+C
从0积到t0,=0.01*(v/m)*ln[(L+t0*m)/L].
只要0.01*(v/m)*ln[(L+t0*m)/L] 大于等于1(即蝇长)即表示可以走到终点。

如果v取0,即在原点踏步。不能达到终点。
L,m都是正常数,如果v取正常数,只要t0取很大的数,总能使式子0.01*(v/m)*ln[(L+t0*m)/L]大于1。

#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 10010
#define ll long long
using namespace std;

int main(void) {
    int T, l, v, m;
    cin >> T;
    while(T--) {
        cin >> l >> v >> m;
        if(v > 0)
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

B - War Chess HDU - 3345

War chess is hh's favorite game:
In this game, there is an N * M battle map, and every player has his own Moving Val (MV). In each round, every player can move in four directions as long as he has enough MV. To simplify the problem, you are given your position and asked to output which grids you can arrive.

In the map:
'Y' is your current position (there is one and only one Y in the given map).
'.' is a normal grid. It costs you 1 MV to enter in this gird.
'T' is a tree. It costs you 2 MV to enter in this gird.
'R' is a river. It costs you 3 MV to enter in this gird.
'#' is an obstacle. You can never enter in this gird.
'E's are your enemies. You cannot move across your enemy, because once you enter the grids which are adjacent with 'E', you will lose all your MV. Here “adjacent” means two grids share a common edge.
'P's are your partners. You can move across your partner, but you cannot stay in the same grid with him final, because there can only be one person in one grid.You can assume the Ps must stand on '.' . so ,it also costs you 1 MV to enter this grid.

这道题做的真难受,一直超时。这道题应该在进入之前就把mv值减了,因为如果放入队列之后,弹出之后再减就不能够保证到达每一步的mv值最大,优先队列就保证了出来的mv值一直是最大的。还有一个坑就是在输入的时候不能判断是不是e,因为这样会把把所有的点遍历。而放入函数中的话就不用遍历所有的点,只是用到哪个点就判断周围是否有敌人。

D - Calculate the expression

HDU - 3347                    

You may find it’s easy to calculate the expression such as:
a = 3
b = 4
c = 5
a + b + c = ?
Isn’t it?

InputThe first line contains an integer stands for the number of test cases.
Each test case start with an integer n stands for n expressions will follow for this case.
Then n – 1 expressions in the format: [variable name][space][=][space][integer] will follow.
You may suppose the variable name will only contain lowercase letters and the length will not exceed 20, and the integer will between -65536 and 65536.
The last line will contain the expression you need to work out.
In the format: [variable name| integer][space][+|-][space][variable name| integer] …= ?
You may suppose the variable name must have been defined in the n – 1 expression and the integer is also between -65536 and 65536.
You can get more information from the sample.
OutputFor each case, output the result of the last expression.Sample Input
3
4
aa = 1
bb = -1
aa = 2
aa + bb + 11 = ?
1
1 + 1 = ?
1
1 + -1 = ?
Sample Output
12
2
0
#include<cstdio>
#include<cstring>
using namespace std;

struct abc
{
    int num;
    char s[25];
}abc[1000000];

int change(int len, char s[] )
{
    int ans=0, a, c=1;
    if(s[0]=='-')
    {
        for(int i=len-1; i>0; i--)
        {
            a=(s[i]-'0')*c;
            ans+=a;
            c*=10;
        }
        return -ans;
    }
    for(int i=len-1; i>=0; i--)
    {
        a=(s[i]-'0')*c;
        ans+=a;
        c*=10;
    }
    return ans;
}
int main()
{
    int t, n, ans=0;
    char z, k[25];
    int flag = 0;
    scanf("%d", &t);
    while(t--)
    {
        memset(k, 0, sizeof(k));
        ans=0;
        scanf("%d", &n);
        for(int i=0; i<n-1; i++)
        {
            scanf("%s = %d", abc[i].s, &abc[i].num);
            //printf("%s =  %d\n",abc[i].s,abc[i].num );
        }
        while(scanf("%s %c ", k, &z))
        {

            if(k[0]>='a' && k[0]<='z')
            {
                for(int i=n-1; i>=0; i--)
                {
                    if(k[0]!=abc[i].s[0])
                        continue;
                    else if(!strcmp(k, abc[i].s))
                    {
                        if(flag)
                        {
                            ans-=abc[i].num;
                            flag = 0;
                        }
                        else
                            ans += abc[i].num;
                             if(z == '-')
                            flag = 1;

                        //printf("abc[i].num= %d\n",abc[i].num );
                        break;
                    }
                }
            }
            else
            {//printf("csdcasd\n");
                int len=strlen(k);
                        if(flag)
                        {
                            ans-=change(len, k);
                            flag = 0;
                        }
                        else
                           ans+=change(len, k);
                    if(z == '-')
                    flag = 1;

            }
            if(z=='=')
                break;
        }
        scanf("%c", &z);
        printf("%d\n", ans);

    }
    return 0;
}

E - coins

HDU - 3348

"Yakexi, this is the best age!" Dong MW works hard and get high pay, he has many 1 Jiao and 5 Jiao banknotes(纸币), some day he went to a bank and changes part of his money into 1 Yuan, 5 Yuan, 10 Yuan.(1 Yuan = 10 Jiao)
"Thanks to the best age, I can buy many things!" Now Dong MW has a book to buy, it costs P Jiao. He wonders how many banknotes at least,and how many banknotes at most he can use to buy this nice book. Dong MW is a bit strange, he doesn't like to get the change, that is, he will give the bookseller exactly P Jiao.
Input T(T<=100) in the first line, indicating the case number.
T lines with 6 integers each:
P a1 a5 a10 a50 a100
ai means number of i-Jiao banknotes.
All integers are smaller than 1000000. Output Two integers A,B for each case, A is the fewest number of banknotes to buy the book exactly, and B is the largest number to buy exactly.If Dong MW can't buy the book with no change, output "-1 -1". Sample Input
3
33 6 6 6 6 6
10 10 10 10 10 10
11 0 1 20 20 20
Sample Output
6 9
1 10
-1 -1

AC代码
这道题最重要的是转换的思想,把求最大值转化为最小值。第一种方法转化的思想是从小面值到大面值一直给钱,当此时可以满足此面值的钱可以完全给足p,并且有余时,此时就把问题转化为,把给多的这部分要用最小的张数抽出来。
第二种方法直接就把最大值的求法转化为最小值的求法。


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
struct banknotes
{
    int num;
    int money;
}a[10];
void init()
{
    memset(a,0,sizeof(a));
    a[1].money = 1;
    a[2].money = 5;
    a[3].money = 10;
    a[4].money = 50;
    a[5].money = 100;

}
int main()
{
    int t;
    scanf("%d", &t);
    while(t --)
    {
        init();
        int p;
        scanf("%d", &p);
        for(int i = 1; i <= 5; i ++)
        {
            scanf("%d", &a[i].num);
        }
        int Min = 0;
        int Max = 0;
        int x = p;
        for(int i = 5;i >= 1; i --)
        {
            if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                Min += (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                int tem = x % a[i].money;
                Min += (x / a[i].money);
                x = tem;
            }
            else
            {
                x -= a[i].money*a[i].num;
                Min += a[i].num;
            }
        }
          if(x)
             Min = -1;
          x = p;
          int b[6] = {0};
          for(int i = 1; i <= 5; i ++)
          {
               if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                b[i] += (x / a[i].money);
                a[i].num -= (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                b[i] += (x / a[i].money + 1);
                a[i].num -= (x / a[i].money + 1);
                x %= a[i].money;
                x -= a[i].money;
                int n = -x;
                for(int j = i - 1; j >= 1; j --)
                {
                    if(n >= a[j].money&&b[j] > 0)
                    {
                        n -= a[j].money;
                        b[j] --;
                        a[j].num ++;
                        if(n == 0)
                    {
                        x = 0;
                        break;
                    }
                        j ++;
                    }
                }
            } else
            {
                b[i] += a[i].num;
                x = x - a[i].num*a[i].money;
                a[i].num = 0;
            }
            if(!x)
                break;
          }
          if(x)
            Max = -1;
          else
            Max = b[1] + b[2] + b[3] + b[4] + b[5];
             printf("%d %d\n", Min, Max);
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
struct banknotes
{
    int num;
    int money;
}a[10];
void init()
{
    memset(a,0,sizeof(a));
    a[1].money = 1;
    a[2].money = 5;
    a[3].money = 10;
    a[4].money = 50;
    a[5].money = 100;

}
int getmin(int p)
{
    int Min = 0;
    int x = p;
        for(int i = 5;i >= 1; i --)
        {
            if(!(x % a[i].money)&&(a[i].num > (x / a[i].money)))
            {
                Min += (x / a[i].money);
                x = 0;
                break;
            }
            if(a[i].num*a[i].money > x)
            {
                int tem = x % a[i].money;
                Min += (x / a[i].money);
                x = tem;
            }
            else
            {
                x -= a[i].money*a[i].num;
                Min += a[i].num;
            }
        }
          if(x)
             Min = -1;
             return Min;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t --)
    {
        init();
        int p;
        scanf("%d", &p);
        int sum = 0;
        int numsum = 0;
        for(int i = 1; i <= 5; i ++)
        {
            scanf("%d", &a[i].num);
            sum += a[i].num*a[i].money;
            numsum += a[i].num;
        }
        int k = sum - p;
        int ansmin = getmin(p);
        int ansmax = numsum - getmin(k);
         if(ansmin == -1)
            ansmax = -1;
             printf("%d %d\n", ansmin, ansmax);
    }
    return 0;
}

基于数据挖掘的音乐推荐系统设计与实现 需要一个代码说明,不需要论文 采用python语言,django框架,mysql数据库开发 编程环境:pycharm,mysql8.0 系统分为前台+后台模式开发 网站前台: 用户注册, 登录 搜索音乐,音乐欣赏(可以在线进行播放) 用户登陆时选择相关感兴趣的音乐风格 音乐收藏 音乐推荐算法:(重点) 本课题需要大量用户行为(如播放记录、收藏列表)、音乐特征(如音频特征、歌曲元数据)等数据 (1)根据用户之间相似性或关联性,给一个用户推荐与其相似或有关联的其他用户所感兴趣的音乐; (2)根据音乐之间的相似性或关联性,给一个用户推荐与其感兴趣的音乐相似或有关联的其他音乐。 基于用户的推荐和基于物品的推荐 其中基于用户的推荐是基于用户的相似度找出相似相似用户,然后向目标用户推荐其相似用户喜欢的东西(和你类似的人也喜欢**东西); 而基于物品的推荐是基于物品的相似度找出相似的物品做推荐(喜欢该音乐的人还喜欢了**音乐); 管理员 管理员信息管理 注册用户管理,审核 音乐爬虫(爬虫方式爬取网站音乐数据) 音乐信息管理(上传歌曲MP3,以便前台播放) 音乐收藏管理 用户 用户资料修改 我的音乐收藏 完整前后端源码,部署后可正常运行! 环境说明 开发语言:python后端 python版本:3.7 数据库:mysql 5.7+ 数据库工具:Navicat11+ 开发软件:pycharm
MPU6050是一款广泛应用在无人机、机器人和运动设备中的六轴姿态传感器,它集成了三轴陀螺仪和三轴加速度计。这款传感器能够实时监测并提供设备的角速度和线性加速度数据,对于理解物体的动态运动状态至关重要。在Arduino平台上,通过特定的库文件可以方便地与MPU6050进行通信,获取并解析传感器数据。 `MPU6050.cpp`和`MPU6050.h`是Arduino库的关键组成部分。`MPU6050.h`是头文件,包含了定义传感器接口和函数声明。它定义了类`MPU6050`,该类包含了初始化传感器、读取数据等方法。例如,`begin()`函数用于设置传感器的工作模式和I2C地址,`getAcceleration()`和`getGyroscope()`则分别用于获取加速度和角速度数据。 在Arduino项目中,首先需要包含`MPU6050.h`头文件,然后创建`MPU6050`对象,并调用`begin()`函数初始化传感器。之后,可以通过循环调用`getAcceleration()`和`getGyroscope()`来不断更新传感器读数。为了处理这些原始数据,通常还需要进行校准和滤波,以消除噪声和漂移。 I2C通信协议是MPU6050与Arduino交互的基础,它是一种低引脚数的串行通信协议,允许多个设备共享一对数据线。Arduino板上的Wire库提供了I2C通信的底层支持,使得用户无需深入了解通信细节,就能方便地与MPU6050交互。 MPU6050传感器的数据包括加速度(X、Y、Z轴)和角速度(同样为X、Y、Z轴)。加速度数据可以用来计算物体的静态位置和动态运动,而角速度数据则能反映物体转动的速度。结合这两个数据,可以进一步计算出物体的姿态(如角度和角速度变化)。 在嵌入式开发领域,特别是使用STM32微控制器时,也可以找到类似的库来驱动MPU6050。STM32通常具有更强大的处理能力和更多的GPIO口,可以实现更复杂的控制算法。然而,基本的传感器操作流程和数据处理原理与Arduino平台相似。 在实际应用中,除了基本的传感器读取,还可能涉及到温度补偿、低功耗模式设置、DMP(数字运动处理器)功能的利用等高级特性。DMP可以帮助处理传感器数据,实现更高级的运动估计,减轻主控制器的计算负担。 MPU6050是一个强大的六轴传感器,广泛应用于各种需要实时运动追踪的项目中。通过 Arduino 或 STM32 的库文件,开发者可以轻松地与传感器交互,获取并处理数据,实现各种创新应用。博客和其他开源资源是学习和解决问题的重要途径,通过这些资源,开发者可以获得关于MPU6050的详细信息和实践指南
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值