Topcode 599 div2 第一题

原创 2013年12月05日 10:54:14

这是一道水题,就是求出数列中最多加上几个之后使得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: MiniatureDachshund
Method: maxMikan
Parameters: vector <int>, int
Returns: int
Method 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: 2
Here, 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: 3
This 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: 6
When she is light enough, she can eat all of the mikan she has bought.
3)  
 
{50}
5000
Returns: 0
When 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;
}


相关文章推荐

SRM 599 DIV2 950

太弱了。。。。这么简单的题也只能比赛之后写。。。。。 roblem Statement   Fox Ciel has a list of names on her...

SRM 599 div2 250 500

Problem Statement   Dachshund is a popular dog breed. In this problem, a miniature dachshun...

柯南1-599(ed2k)

001.云霄飞车杀人事件.mkv  ed2k://|file|001.%E4%BA%91%E9%9C%84%E9%A3%9E%E8%BD%A6%E6%9D%80%E4%BA%BA%E4%BA%8B%E...

菜鸟教程例题---第一题:【1,2,3,4】组成无重复的3位数

题目:有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少? 分析:1.循环:由三位数推出:要做3层循环(定义3个变量,取值范围【1,2,3,4】)           ...

【GDOI 2016 Day2】第一题 SigemaGO

Description原题略,就是给一个n个点m条边的有向图,如果xx–>yy,yy–>zz,那么xx–>zz,边权为ll,这种边最多走limlim次,求1到n的最短路。Solution由于这题范围比...

POJ 2723 2-SAT 第一题

2-SAT的第一题,话说两个月前就看过国家队的论文和PPT,不过当时因为没有好好搞过强连通分量,所以对2-SAT不是很理解。这次回过头来看,思路清晰了不少。 2-SAT一般用在二选一的问题里面,比如...

【JZOJ 4489】【GDOI 2016 Day2】第一题 SigemaGO

Description Analysis这题在GDOI上想到了,可是只有20,so sad 对于那个插近道,只需要做limlim次最短路即可。把图分层,插近道相当于从上一层的图走到这一层的图。 ...

【补题计划】913模拟赛第一题——maze2

首先附上原题 迷宫(maze2.pas/c/cpp) TL:1S ML:128MB 【Description】 你所在的迷宫可以用N行M列的矩阵来描述: # 墙,无法通过 . 地面,可以...

Codeforces #208 div2前两题及思维风暴

昨晚本身准备在宿舍打cf的,结果吵吵闹闹的,也没打成,头也晕晕的,当时看了只看了第一个题,越想越麻烦,最后竟然陷入了误区,半小时也没解,虽然注册了,一发也没交。。。 A. Dima and ...
  • opm777
  • opm777
  • 2013年10月26日 13:17
  • 1305

CF Round#409 Div2 E题DAG最长路+求解线性同余方程以后补

第一次CF啊,和朋友在C4回来的火车上打的。         当时过了c题,第二天早上起来重新改变了数据变成没过了,呜呜呜呜 A:http://codeforces.com/problemset/...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Topcode 599 div2 第一题
举报原因:
原因补充:

(最多只允许输入30个字)