HDU 2602 Bone Collector WA谁来帮忙找找错
The bone collector had a big
bag with a volume of V ,and along his trip of collecting there are a lot of
bones , obviously , different bone has different value and different volume, now
given the each bone’s value along his trip , can you calculate out the maximum
of the total value the bone collector can get ?

cases.
Followed by T cases , each case three lines , the first line contain
two integer N , V, (N <= 1000 , V <= 1000 )representing the number of
bones and the volume of his bag. And the second line contain N integers
representing the value of each bone. The third line contain N integers
representing the volume of each bone.
total value (this number will be less than 231).
5 10
1 2 3 4 5
5 4 3 2 1
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; typedef struct{
int val;
int vol;
float vv;
}Bone; bool compare(Bone a,Bone b)
{
if(a.vv==b.vv){
return a.vol>b.vol;
}
return a.vv>b.vv;
} int main()
{
int t;//t组测试数据
int n;//n个骨头
int v;//书包能装的体积
int now_v=;//已装入的体积
int j1=;//已装入的个数
int sum=;//已装入的总价值
Bone bone[];
cin>>t;
for(int i=;i<t;i++){
scanf("%d %d",&n,&v);
for(int j=;j<n;j++){
scanf("%d",&bone[j].val);
}
for(int j=;j<n;j++){
scanf("%d",&bone[j].vol);
}
for(int j=;j<n;j++){
bone[j].vv=(float)bone[j].val/(float)bone[j].vol;
}
sort(bone,bone+n,compare);
//for(int j=0;j<n;j++){
// cout<<bone[j].vv<<" ";
// cout<<bone[j].val<<" "<<endl;
//}
for(int j=;j<n;j++){
now_v+=bone[j].vol;//循环一次往里装一次
j1++;
if(now_v>=v){
break;
}
}
if(now_v==v){
for(int j=;j<j1;j++){
sum+=bone[j].val;
}
}
if(now_v>v){
for(int j=;j<j1-;j++){
sum+=bone[j].val;
}
}
if(now_v<v){
for(int j=;j<n;j++){
sum+=bone[j].val;
}
}
cout<<sum<<endl;
now_v=;
sum=;
j1=;
}
return ;
}
HDU 2602 Bone Collector WA谁来帮忙找找错的更多相关文章
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 2602 Bone Collector(经典01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
随机推荐
- [译]View components and Inject in ASP.NET MVC 6
原文:http://www.asp.net/vnext/overview/aspnet-vnext/vc 介绍view components view components (VCs) 类似于part ...
- AngularJS API之isXXX()
Angular中保存了很多的判断方法,可以用来验证对象是否符合某种要求,详细的参考代码样例即可 <html> <head> <meta http-equiv=" ...
- 清北学堂模拟day4 捡金币
[问题描述]小空正在玩一个叫做捡金币的游戏.游戏在一个被划分成 n行 n列的网格状场地中进行.每一个格子中都放着若干金币,并且金币的数量会随着时间而不断变化. 小空的任务就是在网格中移动,拾取尽量多的 ...
- Maven 跳过测试目录
在命令行使用 mvn install -Dmaven.skipTests 或 mvn install -Dmaven.test.skip=true 或在pom.xml设置 <build> ...
- jQuery框架分析第一章: 第一个匿名函数
我的jQuery版本为1.7* 这个版本代码比之前的版本优化了很多,结构也清晰了不少,就用最新的吧. 打开jQuery源代码 首先你能看到所有代码被一个 (function(window,undefi ...
- leofs存储总结
1.leofs角色 Account(账户).Bucket(对象桶).Object(对象), gateway.manager0.manager1.storage Account 一个account可以创 ...
- C 文件读写 容易疏忽的一个问题
今天需要解决一个问题,将影像瓦片(一堆jpg文件)分别进行读取,并将所有数据以文件流的方式存入一个.db的文件中, 同时将每个jpg数据在db文件中的位置保存下来,作为index存在.idx文件中. ...
- Spring 事务知识
1.1 Spring注解的各种行为 事物传播注解: @Transactional(propagation=Propagation.REQUIRED) (常用) 如果有事务, 那么加入事务, 没有的话 ...
- 关于cin,getchar(),scanf()的注意事项(转)
问题描述一:(分析scanf()和getchar()读取字符) scanf(), getchar()等都是标准输入函数,一般人都会觉得这几个函数非常简单,没什么特殊的.但是有时候却就是因为使用这些 ...
- 如何用C语言编写病毒‘
怎样用C语言编写病毒在分析病毒机理的基础上,用C语言写了一个小病毒作为实例,用TURBOC2.0实现.[Abstract] This paper introduce the charateristic ...