题目:click here

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int M = 1e5+5;
int n;
int a[M];
int b[M];
bool cmp( int a, int b ) { //从大到小排序
return a > b;
}
int main()
{
while( ~scanf("%d", &n ) ) {
memset( b, 0, sizeof(b) );
for( int i=0; i<n; i++ )
scanf("%d", a+i);
sort( a, a+n, cmp );
int cnt = 0;
for( int i=0; i<n-1; i++ ) {
if( a[i]-a[i+1] <= 1 ) {
b[cnt++] = a[i+1];
i++;
}
}
ll sum = 0;
for( int i=0; i<cnt-cnt%2; i+=2 ) {
sum += (ll)b[i]*(ll)b[i+1];
}
printf("%I64d\n", sum );
}
return 0;
}

CodeForces 525C Ilya and Sticks 贪心的更多相关文章

  1. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #297 (Div. 2) 525C Ilya and Sticks(脑洞)

    C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  4. C. Ilya and Sticks

    C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 1270: Wooden Sticks [贪心]

    点击打开链接 1270: Wooden Sticks [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 31 解决: 11 统计 题目描述 Lialosiu要制作木棍,给n根作为原料 ...

  6. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  7. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  8. C - Ilya and Sticks(贪心)

    Problem description In the evening, after the contest Ilya was bored, and he really felt like maximi ...

  9. Codeforces 1119E Pavel and Triangles (贪心)

    Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...

随机推荐

  1. 【Java】 实现一个简单文件浏览器(1)

    学习Java的Swing的时候写的一个超简单文件浏览器 效果如图: 项目结构: 这里面主要用了两个控件,JTree和JTable 下面先说下左侧的文件树如何实现: 首先是FileTree类,继承于JT ...

  2. 模拟美萍加密狗--Rockey2虚拟狗(一)

    目录(?)[+]   最近受朋友之托做了一个美萍智能电源控制的插件.美萍茶楼从2010版开始支持智能电源控制设备,就是开单.结账时自动开关相应房间的电器,不过官方的设备是有线的.朋友的店已经开了一段时 ...

  3. mongodb 学习初探

    1.去mongodb 官方下载 http://www.mongodb.org/downloads 2.下载php的mongodb扩展 http://files.cnblogs.com/lsl8966/ ...

  4. 解读ECMAScript 6箭头函数

    箭头函数是ECMAScript 6最受关注的更新内容之一.它引入了一种用「箭头」(=>)来定义函数的新语法,它…它碉堡了~.箭头函数与传统的JavaScript函数主要区别在于以下几点: 对 t ...

  5. live555学习经验链接一

    live555学习经验链接:http://xingyunbaijunwei.blog.163.com/blog/#m=0&t=1&c=fks_084071082087086069082 ...

  6. Pain for friend

    For a guy who has experienced his fair share of mysteries,on mystery,I still can't figure out is why ...

  7. 数据结构与算法分析 3.4&3.5 — 链表的交与并算法

    代码: #include <list> template<typename ElementType> list<ElementType> Intersect(con ...

  8. HDU 1104 Remainder( BFS(广度优先搜索))

    Remainder Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  9. Node.mysql

    mysql为常用数据库,下面简单记录在nodejs中操作mysql数据库的简单实现. 环境: nodejs4.2.2 mysql5.7.12 win7 参考资料: npm mysql 代码 var m ...

  10. zoj 3656 2-sat 不错的题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4879 TLE了一下午.然后没办法了 去搜题解 发现思路跟我的差点儿相同 可是 ...