1070. Mooncake (25)
2013-11-26 23:09
253 查看
1070. Mooncake (25)
#include <iostream>
#include <algorithm>
using namespace std;
class CA
{
public:
enum{N=1000};
struct node
{
double weight,profit;
bool operator < (const node& nd) const
{
return profit > nd.profit;
}
};
int n,m;
double allprofit;
node a
;
void run();
};
void CA::run()
{
allprofit=0;
scanf("%d%d",&n,&m);
int i;
for(i=0;i<n;i++) scanf("%lf",&a[i].weight);
for(i=0;i<n;i++)
{
scanf("%lf",&a[i].profit);
a[i].profit/=a[i].weight;
}
sort(a,a+n);
for(i=0;i<n;i++)
{
if(m>=a[i].weight)
{
allprofit+=a[i].profit*a[i].weight;
m-=a[i].weight;
}
else
{
allprofit+=a[i].profit*m;
break;
}
}
printf("%.2f\n",allprofit);
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
class CA
{
public:
enum{N=1000};
struct node
{
double weight,profit;
bool operator < (const node& nd) const
{
return profit > nd.profit;
}
};
int n,m;
double allprofit;
node a
;
void run();
};
void CA::run()
{
allprofit=0;
scanf("%d%d",&n,&m);
int i;
for(i=0;i<n;i++) scanf("%lf",&a[i].weight);
for(i=0;i<n;i++)
{
scanf("%lf",&a[i].profit);
a[i].profit/=a[i].weight;
}
sort(a,a+n);
for(i=0;i<n;i++)
{
if(m>=a[i].weight)
{
allprofit+=a[i].profit*a[i].weight;
m-=a[i].weight;
}
else
{
allprofit+=a[i].profit*m;
break;
}
}
printf("%.2f\n",allprofit);
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
相关文章推荐
- 1070. Mooncake (25)
- nginx之配置文件分析与开源软件配置文件结构设计
- iOS下微信语音播放之切换听筒和扬声器的方法解决方案
- Android界面设计基础:控件焦点4个步骤
- mac下maven安装与使用
- MongoDB实战(12)Replica Sets + Sharding
- MongoDB实战(12)Replica Sets + Sharding
- 庞果网建立基站问题ruby解答
- Android 实现简单的插件化模块化.
- js 获取表格数据(表单变量值)
- 移动APP之HTTP协议
- hdu 4539 郑厂长系列故事——排兵布阵
- Knockout 是什么?
- 多核时代的移动开发(一)-函数式编程思想到来
- 解决ActivityGroup的sub Activity中spinner的WindowManager$BadTokenException的问题
- 基于Lex 和 Yacc 的 C 语言编译器
- windows 2003 域控制器(AD)的常规命令行操作以及修复
- 工作之命令小总结(3):scp命令
- 浅谈SQLite——浅析Lemon
- Compare the value of entity field.