HDU 2602 Bone Collector WA谁来帮忙找找错

时间:2022-12-12 15:08:07
Problem Description
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
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 ?
HDU 2602 Bone Collector  WA谁来帮忙找找错
 
Input
The first line contain a integer T , the number of
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.
 
Output
One integer per line representing the maximum of the
total value (this number will be less than 231).
 
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
 
Sample Output
14
 
解题心得:
  这是一个背包问题,但是还没学会动态规划的方法,只好用贪心法求解,但提交一直是wronganswer,谁看到了请告诉我。
 
#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谁来帮忙找找错的更多相关文章

  1. HDU 2602 Bone Collector 0&sol;1背包

    题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  2. HDOJ&lpar;HDU&rpar;&period;2602 Bone Collector &lpar;DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  3. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  4. HDU 2602 Bone Collector

    http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  5. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  6. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  7. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

  8. HDU 2602 Bone Collector&lpar;01背包裸题&rpar;

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. HDU 2602 - Bone Collector - &lbrack;01背包模板题&rsqb;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

随机推荐

  1. Android随笔之——跨进程通信&lpar;一&rpar; Activity篇

    在Android应用开发中,我们会碰到跨进程通信的情况,例如:你用QQ通讯录打电话的时候会调用系统的拨号应用.某些新闻客户端可以将新闻分享到QQ.微信等应用,这些都是跨进程通信的情况.简而言之,就是一 ...

  2. win7中CIFS挂载和解挂

    1.win7挂载CIFS共享至Z盘指令(用户名:test,密码:123456): net use Z: \\192.168.8.63\ygcd\duanxiuwei 123456 /USER:test ...

  3. Linux下搭建BT服务器

    P2P(Peer to Peer 即对等网络)就是在这种背景下提出的一种网络技术,P2P可以简单地定义为通过直接交换信息,共享计算机资源和服务,对等计算机兼有客户机和服务器的功能.在这种网络中所有的节 ...

  4. 触发器(基本的SR触发器、同步触发器、D触发器)

    一.能够存储1位二值信号的基本单元电路统称为触发器(Filp-Flop) 触发器是构成时序逻辑电路的基本逻辑部件.它有两个稳定状态:“0”和“1”.在不同的输入情况下,它可以被置0状态或1状态,当输入 ...

  5. OpenCV 学习笔记 05 级联分类器CascadeClassifier类

    在人脸检测中,CascadeClassifier 是一个类,该类的作用是(基于官方已经训练好的数据文件 .xml)实例化一个检测器. 1 类 CascadeClassifier 的概述 首先看一下该类 ...

  6. Phpstorm如何连接服务器

    当服务器是Linux的时候不懂指令觉得很懊恼,这个时候直接就可以使用PHPstorm连接服务器操作了: 1丶准备工作 首先你先要准备服务器丶phpstorm这两个吧! 2丶开始配置phpstorm 按 ...

  7. 用MVC5&plus;EF6&plus;WebApi 做一个小功能(一)开场挖坑,在线答题系统

    从哪开始说呢,这几年微软的技术一直在变,像是牟足了劲要累死所有的NET程序员,从WebForm到MVC到现在MPA.SPA .Razor单页,从net2.0一直走到现在.net4.6.2,后面还有一个 ...

  8. LeetCode——remove-duplicates-from-sorted-list

    Question Given a sorted linked list, delete all duplicates such that each element appear only once. ...

  9. hdu 5186&lpar;模拟&rpar;

    zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  10. Win10秘笈:两种方式修改网卡物理地址(MAC)

    每台能够上网的电脑都有网卡,不管是有线还是无线,网卡本身都得有物理地址,也就是MAC(Media Access Control 或 Medium Access Control)地址.这个地址理论上是固 ...