PAT1020月饼
来源:互联网 发布:常见fps游戏的端口 编辑:程序博客网 时间:2024/04/27 18:55
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
double num,profit;
}a[1050];
bool cmp(node a,node b)
{
return a.profit/a.num > b.profit/b.num;
}
int main()
{
int type,total;
int i;
scanf("%d%d",&type,&total);
for(i = 0;i < type;i++)
{
scanf("%lf",&a[i].num);
}
for(i = 0;i < type;i++)
{
scanf("%lf",&a[i].profit);
}
sort(a,a+type,cmp);
double sum = 0,sell = 0;
for(i = 0;i < type;i++)
{
if(total >= a[i].num)
{
sell = a[i].num;
total -= a[i].num;
sum += a[i].profit;
}
else
{
sell = total;
sum += sell * (a[i].profit/a[i].num) ;
break;
}
}
printf("%.2f\n",sum);
return 0;
}
#include<algorithm>
using namespace std;
struct node
{
double num,profit;
}a[1050];
bool cmp(node a,node b)
{
return a.profit/a.num > b.profit/b.num;
}
int main()
{
int type,total;
int i;
scanf("%d%d",&type,&total);
for(i = 0;i < type;i++)
{
scanf("%lf",&a[i].num);
}
for(i = 0;i < type;i++)
{
scanf("%lf",&a[i].profit);
}
sort(a,a+type,cmp);
double sum = 0,sell = 0;
for(i = 0;i < type;i++)
{
if(total >= a[i].num)
{
sell = a[i].num;
total -= a[i].num;
sum += a[i].profit;
}
else
{
sell = total;
sum += sell * (a[i].profit/a[i].num) ;
break;
}
}
printf("%.2f\n",sum);
return 0;
}
这道题一定要考虑全面,我当时就是遗漏了供不应求的情况导致段错误,这个一定要注意,浪费了我好长时间的。
0 0
- PAT1020. 月饼
- PAT1020月饼
- pat1020:月饼
- PAT1020.月饼
- PAT1020 BASIC:月饼 (25)
- PAT1020. 月饼 (25)
- PAT1020 月饼 (25)
- PAT1020月饼 (25)
- pat1020
- pat1020
- pat1020
- PAT1020~~~
- PAT1020
- 月饼
- 月饼
- 月饼
- pat1020. Tree Traversals (25)
- PAT1020 Tree Traversals
- Oracle regexp_substr函数
- 生产订单结算KKS1常见错误
- 一个8583报文的简单例子
- Android DNK开发错误记录
- 如何获得button.tag值?
- PAT1020月饼
- 蒙哥马利幂模运算
- 78. Subsets
- http和socket简介
- 线程钩子
- linux服务器TCP并发连接数优化
- TCP/IP socket编程
- layout.setBackgroundColor(color),直接在colorl里面设置透明度
- 为什么类中的线程函数必须要声明静态?