Problem 1274 - 可怜的lpx
Time Limit: 1000MS   Memory Limit: 65536KB   
Description
可怜的lpx终于在别人的帮助下追上了aqx,可是他那瘦弱的身体想要去强行从aqx那里抢回烟那是不可能的。aqx看着可怜的lpx实在不忍心继续欺负他,便随手扔出来一堆长短不一的木棍,让lpx从中挑出来三根木棍,组成一个三角形,如果这个三角形的周长最大,那么aqx将把烟还给lpx。哎,可怜的lpx。。。
Input
多组数据,每组数据一个n(5<= n <=10^6),代表有n根木棍。
接下来n个整数Xi,代表第i根木棍的长为Xi (1<=Xi<=10^6)。
Output
能组成最大的三角形周长(保证有解)
Sample Input
4
1 2 3 4
Sample Output
9
      很贪心的思想,组成最长周长的3边一定相邻。这样就可以O(N)的枚举了。
 
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int Max_N= ;
int N ,num[Max_N] ;
int cmp(int a ,int b){
return a>b ;
}
inline int ok(int a ,int b ,int c){
return b+c>a ;
}
int gao(){
int i= ;
while(i<=N-){
if(ok(num[i],num[i+],num[i+]))
return num[i]+num[i+]+num[i+] ;
i++ ;
}
}
int main(){
while(scanf("%d",&N)!=EOF){
for(int i= ;i<=N; i++)
scanf("%d",&num[i]) ;
sort(num+,num++N,cmp) ;
printf("%d\n",gao()) ;
}
return ;
}

Problem 1274 - 可怜的lpx的更多相关文章

  1. [题解]poj 1274 The Perfect Stall(网络流)

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  2. [题解]poj 1274 The Prefect Stall

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

  3. poj 1274 The Perfect Stal - 网络流

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  4. poj 1274 The Prefect Stall - 二分匹配

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

  5. hdoj 2102 A计划

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. hdu 2102 A计划(双层BFS)(具体解释)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  7. A计划(bfs)

    A计划 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  8. HDU 2102 A计划(DFS)

    题目链接 Problem Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主 ...

  9. A计划

    A计划 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

随机推荐

  1. Object-C中需要注意的小细节

    --------------------------------------------关于命名------------------------------------------------- 1. ...

  2. (转)如何在eclipse的配置文件里指定jdk路径

    本文转载自:http://songguoliang.iteye.com/blog/1752519 运行eclipse时报如下错误: 在eclipse的配置文件里指定jdk路径,只需在eclipse的配 ...

  3. 在mac上安装svn客户端

    mac 10.8上面,默认是没有svn客户端的,可以通过以下两种方式来安装:    1.单独安装xcode命令行工具,安装完成后,在终端中就可以使用svn命令了,目前版本是1.6.18:    2.去 ...

  4. (C/C++) Interview in English. - Memory Allocation/Deallocation.

    Q: What is the difference between new/delete and malloc/free? A: Malloc/free do not know about const ...

  5. hibernate级联与反向

    cascade:设置本表与关联表之间的级联操作,如:设置为save-update,则插入或更新对象时同时保存或更新另一端的表,但不会产生关联关系数据,除非inverse为false. inverse: ...

  6. Scala控制抽象

    private def filesHere = (new java.io.File(".")).listFiles() def filesEnding(query: String) ...

  7. ADF_Starting系列5_使用ADF开发富Web应用程序之维护User Interface(Part2)

    2014-05-05 Created By BaoXinjian

  8. Report_客制化Excel报表中的XLS标记(案例)

    2014-06-06 Created By BaoXinjian

  9. java浮点型比较大小

    ======1   java浮点型比较大小 Float.parseFloat(String)和Float.valueOf(String).floatValue()的区别 Float.parseFloa ...

  10. 转-ListView的性能优化之convertView和viewHolder

    ListView的性能优化之convertView和viewHolder 2014-05-14 参考:http://www.cnblogs.com/xiaowenji/archive/2010/12/ ...