-
Notifications
You must be signed in to change notification settings - Fork 0
/
B1020.cpp
70 lines (64 loc) · 1.14 KB
/
B1020.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int a, b;
scanf("%d %d", &a, &b);
int kuche[a];
for(int i = 0; i < a; i++){
scanf("%d", &kuche[i]);
}
int jiage[a];
for(int i = 0; i < a; i++){
scanf("%d", &jiage[i]);
}
float junjia[a];
for(int i = 0; i < a; i++){
junjia[i] =float (kuche[i])/jiage[i]
}
float max = -1;
for(int i = 0; i < a; i++){
if()
}
return 0;
}
//方法二用结构体
#include <cstdio>
#include <algorithm>
using namespace std;
struct mooncake{
double store;
double sell;
double price;
}cake[1010];
bool cmp(mooncake a, mooncake b){//按单价从高到低排序
return a.price > b.price;
}
int main()
{
int n;
double D;
scanf("%d %lf", &n, &D);
for(int i = 0; i < n; i++){
scanf("%lf", &cake[i].store);
}
for(int i = 0; i < n; i++){
scanf("%lf", &cake[i].sell);
cake[i].price = cake[i].sell / cake[i].store;
}
sort(cake, cake+n, cmp);//可以对结构体排序
double ans = 0;
for(int i = 0; i < n; i++){
if(cake[i].store <= D){
D -= cake[i].store;
ans += cake[i].sell;
}
else{
ans += cake[i].price*D;
break;
}
}
printf("%.2f\n", ans);
return 0;
}