【BZOJ】【P2697】【特技飞行】【题解】【贪心】
2014-10-25 13:56
471 查看
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2697
水贪心
Code:
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int c[333];
int main(){
cin>>n>>k;
for(int i=1;i<=k;i++)cin>>c[i];
sort(c+1,c+1+k,greater<int>());
int l=1,r=n,ans=0;
for(int i=1;i<=k;i++){
ans+=(r-l)*c[i];
l++;r--;
if(l>=r)break;
}cout<<ans<<endl;
return 0;
}
水贪心
Code:
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int c[333];
int main(){
cin>>n>>k;
for(int i=1;i<=k;i++)cin>>c[i];
sort(c+1,c+1+k,greater<int>());
int l=1,r=n,ans=0;
for(int i=1;i<=k;i++){
ans+=(r-l)*c[i];
l++;r--;
if(l>=r)break;
}cout<<ans<<endl;
return 0;
}
相关文章推荐
- [贪心] BZOJ 2697 特技飞行
- 【bzoj2697】【特技飞行】【贪心】
- 【bzoj2697】 特技飞行 贪心
- bzoj 2697 特技飞行 贪心
- bzoj 2697: 特技飞行 贪心
- 【BZOJ3105】【拟阵】【高斯消元】【贪心】[cqoi2013]新Nim游戏 题解
- 【BZOJ】【P2474】【订单】【题解】【贪心】
- BZOJ2697:特技飞行
- 【BZOJ2697】特技飞行
- 【贪心】BZOJ1060(ZJOI2007)[时态同步]题解
- BZOJ_P2697 特技飞行(贪心)
- BZOJ 1034: [ZJOI2008]泡泡堂BNB 贪心题解
- 【贪心】BZOJ3410(Usaco2009 Dec)[Selfish Grazing 自私的食草者]题解
- 【BZOJ】【P1826&P1528】【JSOI2010】【缓存交换】【题解】【堆+贪心】
- 【BZOJ】【P1907】【树的路径覆盖】【题解】【贪心】
- 【BZOJ】【P3709】【PA2014】【Bohater】【题解】【贪心】
- 【BZOJ】【P2802】【POI2012】【Warehouse Store】【题解】【贪心】
- 【BZOJ】【P3671】【NOI2014】【随机数生成器】【题解】【贪心】
- BZOJ——2697: 特技飞行
- 【题解】期末考试 六省联考 2017 洛谷 P3745 BZOJ 4868 贪心 三分