OpenJudge exercises (C ++) -- question 4110: Santa Claus gift-Santa Clau's Gifts

Source: Internet
Author: User

OpenJudge exercises (C ++) -- question 4110: Santa Claus gift-Santa Clau's Gifts
Question:

Total time limit:
1000 ms
Memory limit:
65536kB
Description

Christmas is approaching. In City A, Santa Claus is preparing to distribute candy. Now there are many different boxes of candy, each box of which has its own value and weight, each box of candy can be split into any combination of bulk and taken away. Santa Claus's reindeer can only bear a certain amount of candy at most. Could you tell me how much candy Santa Claus can take.

Input
The first line consists of two parts: a positive integer n (1 <= n <= 100) for the number of candy boxes, and a positive integer w (0 <w <10000) for the maximum weight of the reindeer ), the two numbers are separated by spaces. Each row of the other n rows corresponds to a box of candy, which is composed of two parts: the value positive integer v and the weight positive integer w, separated by spaces.
Output
Output the maximum total value of the candy that Santa Claus can take away and keep one decimal place. Output as a line ended with a line break.
Sample Input
4 15100 4412 8266 7591 2
Sample output
1193.0
Solution:
#include<stdio.h>#include<iostream>using namespace std;int main(){int times;int weight;int UseNu=0;double AllValue=0;int AllWeight=0;cin>>times>>weight;UseNu=weight;struct MyGift{int Value;int Weit;double perVal;};struct MyGift Gift[times];struct MyGift Temp={0,0,0};for(int i=0;i<times;i&#43;&#43;) cin="">>Gift[i].Value>>Gift[i].Weit;Gift[i].perVal=(double)(Gift[i].Value)/(double)(Gift[i].Weit); AllWeight+=Gift[i].Weit; AllValue+=Gift[i].Value; }  for(int j=0;j<times;j&#43;&#43;) int="" h="1;h<times;h++)" temp="Gift[h-1];" return="" allvalue="0;" z="0;z<times;z++)" usenu-="Gift[z].Weit;" pre=""><p></p>   </times;j&#43;&#43;)></times;i&#43;&#43;)></iostream></stdio.h>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.