设为首页 加入收藏

TOP

UVA10026
2014-11-23 19:48:33 来源: 作者: 【 】 浏览:3
Tags:UVA10026

使用贪心按照性价比排序即可,唯一需要注意的就是它的输出格式。

The outputs of two consecutive cases will be separated by a blank line.

#include   
#include   
using namespace std;  
  
struct Node{  
    int index;    //每双鞋子的索引   
    double time;  
    double fine;  
    double cost;   //性价比   
};  
Node test[1001];  
bool cmp(const Node& node1,const Node& node2);  
int main()  
{  
    int  testNumber;  
    cin>>testNumber;  
    for(int i=1;i<=testNumber;i++)  //测试的数目   
    {  
        int shoseNumber;  
        cin>>shoseNumber;  
        for(int j=0;j>test[j].time;  
            cin>>test[j].fine;  
            test[j].index=j+1;   //计算性价比   
            test[j].cost=test[j].fine/test[j].time;  
        }  
        sort(test,test+shoseNumber,cmp);  
        for(int h=0;hnode2.cost;  
    else  
        return node1.cost
#include
using namespace std;

struct Node{
    int index;    //每双鞋子的索引
    double time;
    double fine;
    double cost;   //性价比
};
Node test[1001];
bool cmp(const Node& node1,const Node& node2);
int main()
{
    int  testNumber;
    cin>>testNumber;
    for(int i=1;i<=testNumber;i++)  //测试的数目
    {
        int shoseNumber;
        cin>>shoseNumber;
        for(int j=0;j>test[j].time;
            cin>>test[j].fine;
            test[j].index=j+1;   //计算性价比
            test[j].cost=test[j].fine/test[j].time;
        }
        sort(test,test+shoseNumber,cmp);
        for(int h=0;hnode2.cost;
    else
        return node1.cost 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU4570----Multi-bit Trie----简.. 下一篇CF 337A(Puzzles-暴力枚举)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·求navicat for mysql (2025-12-26 13:21:33)
·有哪位大哥推荐一下m (2025-12-26 13:21:30)
·MySQL下载与安装教程 (2025-12-26 13:21:26)
·Linux_百度百科 (2025-12-26 12:51:52)
·Shell 流程控制 | 菜 (2025-12-26 12:51:49)