UVa 11824 - A Minimum Land Price
2015-12-18 17:59
176 查看
題目:要買一系列的島,島的價格已知,需要支付的總數為 2*L[fristbuy]^1 + 2*L[secondbuy]^2 + ... ,問最少支付多少。
分析:貪心,排序。直接按價值排序從大到小購買即可。
說明:╮(╯▽╰)╭。
分析:貪心,排序。直接按價值排序從大到小購買即可。
說明:╮(╯▽╰)╭。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int L[41]; int main() { int t; while (~scanf("%d",&t)) while (t --) { int n = 0; while (scanf("%d",&L ) && L ) n ++; sort(L, L+n); long long ans = 0LL, pow; for (int i = n-1; i >= 0; -- i) { pow = 2LL; for (int j = n; j > i; -- j) pow = pow*L[i]; ans += pow; } if (ans > 5000000) printf("Too expensive\n"); else printf("%lld\n",ans); } return 0; }
相关文章推荐
- vretica自动收集统计信息脚本
- IOS传值的几种方式
- 总结 推广app
- z-index无效
- 安卓JNI--小项目试验计时器
- objective-c之谓词
- 摘抄的一些js
- 黑马程序员--面向对象
- daemon函数的原理及使用详解
- Java提高篇(二八)------TreeSet
- 网路图片加载
- centos下配置sftp且限制用户访问目录[转]
- “400 Bad Request”解决办法及Unity下载文件保存到本地
- eclipse取消自动更新
- Oracle12c中SQL性能优化(SQL TUNING)新特性之自动重优化(automatic reoptimization)
- APP测试汇总
- 计算机二级C 想过必看
- [.Net码农]FastReport.Net使用
- Appium--环境搭建
- "留拍"-注册/登录详解