POJ3253 Fence Repair
来源:互联网 发布:dns域名系统 编辑:程序博客网 时间:2024/06/15 11:25
注意题目的数据大小,ans要用long long类型。
#include <iostream>#include<algorithm>using namespace std;int n,b[200005];void solve();int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>b[i]; } sort(b,b+n); solve(); return 0;}void solve(){ long long ans=0; int j; for(int i=0;i<n-1;i++){ int min1=b[i],min2=b[i+1]; int t=min1+min2; ans+=t; for(j=i+2;j<n;j++){ if(b[j]<t){ b[j-1]=b[j]; } else break; } b[j-1]=t; /*for(int j=i+1;j<n;j++){ cout<<b[j]; } cout<<endl;*/ } if(n==1) ans=b[0]; cout<<ans<<endl;}
0 0
- POJ3253 Fence Repair
- poj3253 Fence Repair( 贪心 )
- poj3253 Fence Repair
- poj3253 Fence Repair
- poj3253 Fence Repair---赫夫曼树
- poj3253 Fence Repair
- POJ3253 Fence Repair
- POJ3253 Fence Repair
- POJ3253--Fence Repair
- POJ3253 Fence Repair(贪心)
- POJ3253 Fence Repair
- poj3253 Fence Repair
- Poj3253—Fence Repair
- POJ3253-Fence Repair
- POJ3253-Fence Repair
- [POJ3253]-Fence Repair
- POJ3253-Fence Repair
- POJ3253 Fence Repair
- 7. Reverse Integer
- 用java打印日历
- Java callback-JAVA实现回调
- leetcode 165 Compare Version Numbers C++
- SSM框架+WebSocket实现网页聊天(Spring+SpringMVC+MyBatis+WebSocket)
- POJ3253 Fence Repair
- Android 颜色对照表
- 第四章 4.7 条件运算符
- MYSQL : localhost 和 127.0.0.1
- HDU 4445 Running Rabbits(模拟)
- 素数判断
- 获取spring的ApplicationContext几种方式
- Webx的执行流程
- C++和java对比