PAT basic 1020
2017-08-02 13:07
162 查看
#include<iostream> #include<algorithm> using namespace std; struct mooncake { float mount; float price; float unit; }; int cmp(mooncake a,mooncake b) { return a.unit > b.unit; } int main() { int n; cin >> n; int need; cin >> need; mooncake *a = new mooncake ; for(int i = 0; i < n; i++) { cin >> a[i].mount; } for(int i = 0; i < n; i++) { cin >> a[i].price; } for(int i = 0; i < n; i++) { a[i].unit = a[i].price / a[i].mount; } sort(a, a + n, cmp); float result = 0.0; for(int i = 0; i < n; i++) { if(a[i].mount <= need) { result += a[i].price; } else { result += a[i].unit * need; break; } need -= a[i].mount; } //cout << result; 格式错误 printf("%.2f",result); return 0; }
相关文章推荐
- PAT Basic Level 1020. 月饼(25)
- PAT Basic Level Practise 1020坑点
- PAT (Basic Level)1020. 月饼
- pat 1070 (同basic level 1020)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT(basic level) 1020 月饼(25)
- 刷题训练——PAT (Basic Level)-1020
- PAT1020 BASIC:月饼 (25)
- 浙大 pat Basic Level 1020
- PAT (Basic) 1016~1020
- PAT BASIC 1020 月饼
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- Pat(Basic Level)Practice--1020(月饼)
- PAT Basic 1020. 月饼 (25)(C语言实现)
- PAT Basic 1020
- PAT(Basic Level)_1020_月饼
- PAT BASIC LEVEL 1020. 月饼 (25)
- PAT basic1016-1020(Python版)
- PAT (Basic Level) Practise (中文)1020. 月饼 (25)
- PAT_1020(Basic Level)Practise C语言实现代码