HDU:1009 FatMouse' Trade

FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 68716    Accepted Submission(s): 23432


Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
 

Input
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
 

Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
 

Sample Input
5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1
 

Sample Output
13.333 31.500

题目代码:

#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct infor {     double value;     double cost;     double aver; }a[1004]; bool cmp(infor p1,infor p2) {     return p1.aver < p2.aver; } int main() {     int M,N;//M磅猫粮,N个房间     double _max;     while(~scanf("%d%d",&M,&N))     {         if(M < 0 && N < 0)             break;         for(int i = 0; i < N; i++)         {             scanf("%lf%lf",&a[i].value,&a[i].cost);             a[i].aver = a[i].cost/a[i].value;         }         sort(a,a+N,cmp);//按单位价格进行排序         _max = 0;         for(int i = 0; i < N; i++)         {                 if(M >= a[i].cost)                 {                     _max += a[i].value;                     M = M - a[i].cost;                 }                 else                 {                     _max += (M*a[i].value)/a[i].cost;                     break;                 }         }         printf("%.3lf\n",_max);     }     return 0; }

### 创建基于Maven构建的Spring Boot项目 #### 使用VSCode创建Spring Boot Maven项目 为了在Visual Studio Code (VSCode) 中创建一个新的Spring Boot Maven项目,需遵循一系列配置操作。确保已安装Java Development Kit (JDK),设置好环境变量以便命令行工具能够识别`java`和`mvn`命令。 安装必要的扩展来支持Java开发以及Maven项目管理,在VSCode市场中搜索安装以下两个官方推荐插件: - **Extension Pack for Java**: 提供完整的Java语言支持。 - **Maven for Java**: 增强对Maven项目的编辑体验。 完成上述准备之后,按照下面的方法启动新项目创建工作[^1]。 #### 初始化新的Maven项目 通过终端执行如下指令快速搭建基础框架: ```bash mkdir my-springboot-app && cd $_ mvn archetype:generate \ -DgroupId=com.example \ -DartifactId=my-springboot-app \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false ``` 这段脚本会利用Maven Archetype机制自动生成标准目录结构与初始文件集。注意替换`com.example`为实际的应用程序包名,调整`my-springboot-app`以匹配期望的工程名称。 #### 添加Spring Boot依赖项 打开生成的`pom.xml`文件,向其中加入Spring Boot Starter Parent作为父POM,引入所需的Starters模块,比如Web服务支持等。修改后的XML片段可能看起来像这样: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.0</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ``` 保存更改后,VSCode中的Maven插件将会自动下载相应的库资源解析路径。 #### 配置运行参数 对于希望直接从IDE内部调试或测试应用的情况,可以在`.vscode/launch.json`内定义特定于Spring Boot应用程序的任务配置。例如: ```json { "version": "0.2.0", "configurations": [ { "type": "java", "name": "Launch MyApplication", "request": "launch", "mainClass": "com.example.MyApplication" } ] } ``` 这里假设主类名为`MyApplication.java`且位于指定包下;如果实际情况不同,则应相应地更新此字段值。 最后一步是在根目录下的`src/main/java/com/example/`位置新建一个简单的入口点实现——即包含`public static void main(String[] args)`方法的类文件,用于触发整个系统的初始化过程。 至此,已经成功建立了一个基本可用的Spring Boot Maven项目模板,可以直接编译、打包甚至部署至容器环境中进一步探索其功能特性了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值