Topcode 599 div2 第一题
来源:互联网 发布:念奴娇鸟儿问答知乎 编辑:程序博客网 时间:2024/04/30 07:47
这是一道水题,就是求出数列中最多加上几个之后使得weight的和保持小于等于5000.....贪心就行了....
Problem Statement
Dachshund is a popular dog breed. In this problem, a miniature dachshund is defined as a dachshund whose weight is not more than 5,000 grams.Lun the miniature dachshund loves mikan (satsuma oranges). She has just bought some mikan. You are given a vector <int>mikan. It gives the weight of all mikan she bought. For each valid i,mikan[i] is the weight of the i-th mikan in grams.
You are also given an int weight. Currently, Lun weighs weight grams. When she eats i-th mikan, her weight increases by mikan[i] grams. If she eats multiple mikan, her weight increases by their total weight. She cannot eat just a part of a mikan. In other words, if she chooses to eat a mikan, she eats it completely.
She wants to remain being a miniature dachshund. That is, she wants her weight not to exceed 5,000 grams. Under this condition, calculate and return the maximum number of mikan Lun can eat.
Definition
Class:MiniatureDachshundMethod:maxMikanParameters:vector <int>, intReturns:intMethod signature:int maxMikan(vector <int> mikan, int weight)(be sure your method is public)Constraints
-mikan will contain between 1 and 50 elements, inclusive.-Each element of mikan will be between 50 and 200, inclusive.-weight will be between 3,000 and 5,000, inclusive.Examples
0){100, 100, 100, 100, 100}
4750
Returns: 2Here, Lun weighs 4,750 grams and has bought 5 mikan, each of which weighs 100 grams. When she eats 2 of these, her weight will be 4,950 grams. She should not eat more.1)
{100, 100, 100, 100, 50}
4750
Returns: 3This time, one of the mikan is smaller. She can eat it with 2 of the 100-gram mikan. Note that her weight is allowed to be exactly 5,000 grams.2)
{120, 90, 130, 100, 110, 80}
3000
Returns: 6When she is light enough, she can eat all of the mikan she has bought.3)
{50}
5000
Returns: 0When her weight is already 5,000 grams, she should not eat anything.4)
{200, 50, 200, 50, 200, 50, 200, 50}
4800
Returns: 4
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#define M 10010#define INF 1 << 30;using namespace std;class MiniatureDachshund{public: int maxMikan(vector <int> mikan, int weight) { int n = mikan.size(); int i, f[100]; for(i = 0; i < n; i++) f[i] = mikan[i]; sort(f, f+n); int cnt = 0; for(i = 0; i < n; i++) { weight += f[i]; if(weight <= 5000) cnt ++; else break; } return cnt; }};int main(){ return 0;}
- Topcode 599 div2 第一题
- TopCode插件配置
- TopCode google题目
- Topcode SRM 556
- topcode srm SRM 557
- SRM 599 DIV2 950
- codeforces147 div2 C题
- SRM 599 div2 250 500
- Topcoder 551 DIV2 第三题
- codeforces 136 div2 D题
- CodeForces #156 Div2 D题
- codeforce 168#div2 B题
- CF 199 div2 B题
- CF Div2-206-C题
- Codeforece#219(DIV2) C题
- codedorces 260 div2 A题
- codeforces 260 div2 B题
- codeforces 260 div2 C题
- silverlight与页面交互
- 自动调整toolkit:ListPicker大小xaml
- STM32之NVIC理解
- navigator.onLine 离线检测
- 获取amlogic源码
- Topcode 599 div2 第一题
- 交换机的背板容量、交换容量和包转发能力2
- Base64编码及编码性能测试 [改进]
- iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
- 本博客说明
- chrome启动参数设置
- 电话本------改进值分离命令和参数
- 10^4号遇骗遭遇未果の愤怒版
- mobileazure和高德地图查看已记录位置