| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 280 人关注过本帖
标题:帮忙看看这题目哪错了?
只看楼主 加入收藏
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
收藏
已结贴  问题点数:10 回复次数:2 
帮忙看看这题目哪错了?
Problem E:Rotten Ropes

Time Limit:1000MS  Memory Limit:65536K
Total Submit:123 Accepted:83

Description

Suppose we have n ropes of equal length and we want to use them to lift some heavy object. A tear-off weight t is associated to each rope, that is, if we try to lift an object, heavier than t with that rope, it will tear off. But we can fasten a number of ropes to the heavy object (in parallel), and lift it with all the fastened ropes. When using k ropes to lift a heavy object with weight w, we assume that each of the k ropes, regardless of its tear-off weight, is responsible for lifting a weight of w/k. However, if w/k > t for some rope with tear-off weight of t, that rope will tear off. For example, three ropes with tear-off weights of 1, 10, and 15, when all three are fastened to an object, can not lift an object with weight more than 3, unless the weaker one tears-off. But the second rope, may lift by itself, an object with weight at most 10. Given the tear-off weights of n ropes, your task is to find the weight of the heaviest object that can be lifted by fastening a subset of the given ropes without any of them tearing off.

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 1000) which is the number of ropes. Following the first line, there is a single line containing n integers between 1 and 10000 which are the tear-off weights of the ropes, separated by blank characters.

Output

Each line of the output should contain a single number, which is the largest weight that can be lifted in the corresponding test case without tearing off any rope chosen

Sample Input


2
3
10 1 15
2
10 15

Sample Output


20
20


#include<stdio.h>
main()
{
    int f,t,n,num[1005],i,j,k,max;
    while(scanf("%d",&t)!=EOF)
    {
        for(i=1;i<=t;i++)
        {
            scanf("%d",&n);
            for(j=0;j<n;j++)
            {
                scanf("%d",&num[j]);
            }
            for(j=1;j<=n-1;j++)
            {
                for(k=0;k<n-j;k++)
                {
                    if(num[k]>num[k+1])
                    {
                        f=num[k];
                        num[k]=num[k+1];
                        num[k+1]=f;
                    }
                }
            }
            max=num[0]*n;
            for(j=0;j<n;j++)
            {
                if(num[j]*(n-j)>max)
                max=num[j]*(n-j);
            }
            printf("%d\n",max);
        }
    }
}
搜索更多相关主题的帖子: Memory number 
2011-07-05 16:17
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
收藏
得分:0 
回复 2楼 C小易
没办法,都是英文题目
2011-07-05 16:24
快速回复:帮忙看看这题目哪错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014701 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved