HDU 5003 Osu!

本文介绍了一个osu!音乐游戏积分系统的计算器实现,包括输入处理、数据排序和积分计算等关键步骤。

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

Osu!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1398    Accepted Submission(s): 655
Special Judge


Problem Description
Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring system, which evaluates your performance. Each song you have played will have a score. And the system will sort all you scores in descending order. After that, the i-th song scored a i will add 0.95^(i-1)*a i to your total score.

Now you are given the task to write a calculator for this system.
 

Input
The first line contains an integer T, denoting the number of the test cases.

For each test case, the first line contains an integer n, denoting the number of songs you have played. The second line contains n integers a 1, a 2, ..., a n separated by a single space, denoting the score of each song.

T<=20, n<=50, 1<=a i<=500.
 

Output
For each test case, output one line for the answer.

Your answers will be considered correct if its absolute error is smaller than 1e-5.
 

Sample Input
  
1 2 530 478
 

Sample Output
  
984.1000000000
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5431  5430  5429  5428  5427 
 

2014年ACM/ICPC鞍山赛区的一道签到题。

#include <stdio.h>
#include <math.h>
#include <algorithm>
#define N 55
using namespace std;
double num095[N];
int a[N];
void gettable()
{
        for(int i=0;i<=49;i++)
                num095[i]=pow(0.95,i);
}
bool cmp(int a,int b)
{
        return a>b;
}
int main()
{
        int t;
        scanf("%d",&t);
        gettable();
        while(t--)
        {
                int n;
                scanf("%d",&n);
                for(int i=1;i<=n;i++)
                        scanf("%d",&a[i]);
                sort(a+1,a+n+1,cmp);
                double sum=0;
                for(int i=1;i<=n;i++)
                        sum+=a[i]*1.0000*num095[i-1];
                printf("%lf\n",sum);
        }
        return 0;
}


[OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c: In function 'gps_init': [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:115:5: error: unknown type name 'hi_uart_attribute'; did you mean '__has_attribute'? [OHOS ERROR] hi_uart_attribute config = { [OHOS ERROR] ^~~~~~~~~~~~~~~~~ [OHOS ERROR] __has_attribute [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:116:9: error: field name not in record or union initializer [OHOS ERROR] .baud_rate = 9600, // NEO-6M默认波特率 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:116:9: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:9: error: field name not in record or union initializer [OHOS ERROR] .data_bits = HI_UART_DATA_BIT_8, // 8数据 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:9: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: error: 'HI_UART_DATA_BIT_8' undeclared (first use in this function); did you mean 'HI_ERR_DMA_BUSY'? [OHOS ERROR] .data_bits = HI_UART_DATA_BIT_8, // 8数据 [OHOS ERROR] ^~~~~~~~~~~~~~~~~~ [OHOS ERROR] HI_ERR_DMA_BUSY [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: note: each undeclared identifier is reported only once for each function it appears in [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: warning: excess elements in scalar initializer [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:117:22: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:9: error: field name not in record or union initializer [OHOS ERROR] .stop_bits = HI_UART_STOP_BIT_1, // 1停止 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:9: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: error: 'HI_UART_STOP_BIT_1' undeclared (first use in this function); did you mean 'HI_UART_DATA_BIT_8'? [OHOS ERROR] .stop_bits = HI_UART_STOP_BIT_1, // 1停止 [OHOS ERROR] ^~~~~~~~~~~~~~~~~~ [OHOS ERROR] HI_UART_DATA_BIT_8 [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: warning: excess elements in scalar initializer [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:118:22: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:9: error: field name not in record or union initializer [OHOS ERROR] .parity = HI_UART_PARITY_NONE, // 无校验 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:9: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: error: 'HI_UART_PARITY_NONE' undeclared (first use in this function); did you mean 'HI_UART_DATA_BIT_8'? [OHOS ERROR] .parity = HI_UART_PARITY_NONE, // 无校验 [OHOS ERROR] ^~~~~~~~~~~~~~~~~~~ [OHOS ERROR] HI_UART_DATA_BIT_8 [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: warning: excess elements in scalar initializer [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:119:19: note: (near initialization for 'config') [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:9: error: field name not in record or union initializer [OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:9: note: (near initialization for 'config') [OHOS ERROR] In file included from ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_io.h:26:0, [OHOS ERROR] from ../../../vendor/pzkj/pz_hi3861/common/bsp/include/bsp_gps.h:6, [OHOS ERROR] from ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:1: [OHOS ERROR] ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_types_base.h:284:26: warning: excess elements in scalar initializer [OHOS ERROR] #define HI_TRUE 1 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:24: note: in expansion of macro 'HI_TRUE' [OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO [OHOS ERROR] ^~~~~~~ [OHOS ERROR] ../../../device/hisilicon/hispark_pegasus/sdk_liteos/include/hi_types_base.h:284:26: note: (near initialization for 'config') [OHOS ERROR] #define HI_TRUE 1 [OHOS ERROR] ^ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:120:24: note: in expansion of macro 'HI_TRUE' [OHOS ERROR] .fifo_enable = HI_TRUE // 启用FIFO [OHOS ERROR] ^~~~~~~ [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:124:18: warning: implicit declaration of function 'hi_uart_init'; did you mean 'uart0_init'? [-Wimplicit-function-declaration] [OHOS ERROR] hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config); [OHOS ERROR] ^~~~~~~~~~~~ [OHOS ERROR] uart0_init [OHOS ERROR] ../../../vendor/pzkj/pz_hi3861/common/bsp/src/bsp_gps.c:124:31: error: 'HI_UART_IDX_2' undeclared (first use in this function); did you mean 'HI_GPIO_IDX_2'? [OHOS ERROR] hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config); [OHOS ERROR] ^~~~~~~~~~~~~ [OHOS ERROR] HI_GPIO_IDX_2 [OHOS ERROR] you can check build log in D:\hi3861\hi3861_hdu_iot_application\src\out\hispark_pegasus\wifiiot_hispark_pegasus\build.log [OHOS ERROR] command: "D:\hi3861\hi3861_hdu_iot_application\src\prebuilts\build-tools\win64-x64\bin\ninja.exe -w dupbuild=warn -C D:\hi3861\hi3861_hdu_iot_application\src\out\hispark_pegasus\wifiiot_hispark_pegasus" failed [OHOS ERROR] return code: 1 [OHOS ERROR] execution path: D:\hi3861\hi3861_hdu_iot_application\src scons: *** [src\out\hispark_pegasus\wifiiot_hispark_pegasus\target.elf] Error -1请根据该错误对VSCODE以下代码进行修改#ifndef BSP__GPS_H__ #define BSP__GPS_H__ #include "cmsis_os2.h" #include "hi_io.h" #include "hi_gpio.h" #include <stdio.h> #include <string.h> #include "bsp_uart.h" #include "hi_errno.h" // GPS 数据结构定义 typedef struct { float longitude; // 经度 (度) float latitude; // 纬度 (度) char nshemi; // 北纬/南纬 (N/S) char ewhemi; // 东经/西经 (E/W) struct { uint8_t hour; // UTC 小时 uint8_t min; // UTC 分钟 uint8_t sec; // UTC 秒 } utc; uint8_t fixmode; // 定模式 uint8_t posslnum; // 参与定的卫星数 float altitude; // 海拔高度 (米) } nmea_msg; // 定义UART2引脚配置 #define GPS_UART_IDX HI_UART_IDX_2 #define GPS_BAUDRATE 9600 // NEO-6M默认波特率 // 函数声明 void gps_init(void); void gps_parse_nmea(nmea_msg *gps, const char *buf); void gps_show_data(const nmea_msg *gps); #endif#include "bsp_gps.h" #include <stdlib.h> #include "bsp_uart.h" // 添加必要的UART头文件 // 查找逗号置 // 计算m的n次方 static uint32_t NMEA_Pow(uint8_t m, uint8_t n) { uint32_t result = 1; while (n--) result *= m; return result; } // 查找逗号置(修改为接受const指针) uint8_t nmea_comma_pos(const uint8_t *buf, uint8_t cx) { const uint8_t *p = buf; while (cx) { if (*buf == '*' || *buf < ' ' || *buf > 'z') return 0xFF; // 错误终止符 if (*buf == ',') cx--; buf++; } return buf - p; } // 字符串转数字(修改为接受const指针) int nmea_str2num(const uint8_t *buf, uint8_t *dx) { const uint8_t *p = buf; uint32_t ires = 0, fres = 0; uint8_t ilen = 0, flen = 0, i; uint8_t mask = 0; int res; while (1) { if (*p == '-') { mask |= 0x02; p++; } // 负数标记 if (*p == ',' || *p == '*') break; // 结束符 if (*p == '.') { mask |= 0x01; p++; } // 小数点 else if (*p > '9' || *p < '0') { // 非法字符 ilen = 0; flen = 0; break; } if (mask & 0x01) flen++; else ilen++; p++; } if (mask & 0x02) buf++; // 跳过负号 for (i = 0; i < ilen; i++) // 整数部分 ires += NMEA_Pow(10, ilen - 1 - i) * (buf[i] - '0'); if (flen > 5) flen = 5; // 最多5小数 if (dx) *dx = flen; // 安全处理空指针 for (i = 0; i < flen; i++) // 小数部分 fres += NMEA_Pow(10, flen - 1 - i) * (buf[ilen + 1 + i] - '0'); res = ires * NMEA_Pow(10, flen) + fres; if (mask & 0x02) res = -res; return res; } // 解析 GPRMC 语句 static void parse_gprmc(nmea_msg *gps, const char *buf) { const char *p = strstr(buf, "GPRMC"); if (!p) return; // 显式类型转换解决警告(函数参数已改为const uint8_t*) uint8_t pos = nmea_comma_pos((const uint8_t *)p, 1); // UTC 时间 if (pos != 0xFF) { uint32_t time = nmea_str2num((const uint8_t *)(p + pos), NULL); gps->utc.hour = time / 10000; gps->utc.min = (time % 10000) / 100; gps->utc.sec = time % 100; } pos = nmea_comma_pos((const uint8_t *)p, 3); // 纬度 if (pos != 0xFF) { float lat = nmea_str2num((const uint8_t *)(p + pos), NULL) / 100000.0f; gps->latitude = (int)(lat / 100) + (lat - (int)(lat / 100) * 100) / 60.0f; } pos = nmea_comma_pos((const uint8_t *)p, 4); // 纬度半球 if (pos != 0xFF) gps->nshemi = *(p + pos); pos = nmea_comma_pos((const uint8_t *)p, 5); // 经度 if (pos != 0xFF) { float lon = nmea_str2num((const uint8_t *)(p + pos), NULL) / 100000.0f; gps->longitude = (int)(lon / 100) + (lon - (int)(lon / 100) * 100) / 60.0f; } pos = nmea_comma_pos((const uint8_t *)p, 6); // 经度半球 if (pos != 0xFF) gps->ewhemi = *(p + pos); } // 主解析函数 void gps_parse_nmea(nmea_msg *gps, const char *buf) { if (strstr(buf, "$GPRMC")) parse_gprmc(gps, buf); // 修正:移除多余空格 // 可扩展其他语句解析 (如GPGGA, GPGSA等) } void gps_init(void) { // 初始化GPIO子系统 (必须首先调用) hi_gpio_init(); // ===== 配置TX引脚 (GPIO11 - 输出) ===== hi_io_set_pull(HI_IO_NAME_GPIO_11, HI_IO_PULL_UP); // 上拉模式 hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD); // UART TX功能 hi_gpio_set_dir(HI_IO_NAME_GPIO_11, HI_GPIO_DIR_OUT); // 输出方向 // ===== 配置RX引脚 (GPIO12 - 输入) ===== hi_io_set_pull(HI_IO_NAME_GPIO_12, HI_IO_PULL_NONE); // 浮空模式(推荐) hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD); // UART RX功能 hi_gpio_set_dir(HI_IO_NAME_GPIO_12, HI_GPIO_DIR_IN); // 输入方向 // ===== UART参数配置 ===== hi_uart_attribute config = { .baud_rate = 9600, // NEO-6M默认波特率 .data_bits = HI_UART_DATA_BIT_8, // 8数据 .stop_bits = HI_UART_STOP_BIT_1, // 1停止 .parity = HI_UART_PARITY_NONE, // 无校验 .fifo_enable = HI_TRUE // 启用FIFO }; // 初始化UART2 hi_u32 ret = hi_uart_init(HI_UART_IDX_2, &config); if (ret != HI_ERR_SUCCESS) { printf("GPS UART init failed! Error: 0x%X\n", ret); } } // 显示GPS数据 void gps_show_data(const nmea_msg *gps) { printf("Longitude: %.5f%c\n", gps->longitude, gps->ewhemi); printf("Latitude: %.5f%c\n", gps->latitude, gps->nshemi); printf("UTC Time: %02d:%02d:%02d\n", gps->utc.hour, gps->utc.min, gps->utc.sec); printf("Satellites: %d\n", gps->posslnum); printf("Altitude: %.1fm\n", gps->altitude); }
最新发布
07-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值