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++) 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++) 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++)></times;i++)></iostream></stdio.h>