题目传送门

 /*
题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1
贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; typedef long long ll; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
ll x[MAXN];
int vis[MAXN]; int main(void) //Codeforces Round #297 (Div. 2) C. Ilya and Sticks
{
int n;
while (scanf ("%d", &n) == )
{
memset (x, , sizeof (x));
for (int i=; i<=n; ++i) scanf ("%d", &a[i]);
sort (a+, a++n);
int p = ;
for (int i=n; i>=; --i)
{
if (a[i] == a[i-]) {x[p++] = a[i]; i--;}
else if (a[i] == a[i-] + ) {x[p++] = a[i-]; i--;}
} if (p < ) puts ("");
else
{
ll sum = ; x[p] = ;
for (int i=; i<p; i+=)
{
sum += (x[i] * x[i+]);
}
if (p & ) sum -= x[p-];
printf ("%I64d\n", sum);
}
} return ;
} /*
4
2 4 4 2
4
2 2 3 5
4
100003 100004 100005 100006
5
1 1 1 1 1
10
3 3 5 4 2 2 5 6 7 5
*/

贪心 Codeforces Round #297 (Div. 2) C. 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) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  4. Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索

    Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  ...

  5. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  6. Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和

    Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx ...

  7. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  8. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...

  9. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

随机推荐

  1. java 调用ant的自己定义task,默认不是build.xml 的一点问题

    java  调用ant的自己定义task, File buildFile = new File(".//ee-build.xml");         // 创建一个ANT项目   ...

  2. bash shell中的特殊用法

    1 ${BASH_SOURCE-$0} 表示当前正在执行的脚本的完整路径. 2 cd -P 以物理路径进入 /usr/localhadoop现在链到/home/houzhizhen/usr/local ...

  3. (27) java web的struts2框架的使用-基于表单的多文件上传

    和单个文件上传配置都是一样的,只是在action中接受参数时候,接受的是数组,不再是单个的文件. 一,action的实现: public class MutableFilesUpload extend ...

  4. 自己写的canvas 手写画板

    <!DOCTYPE html> <html> <head> <title>canvas</title> <meta charset=& ...

  5. Spring的声明式事务

    1.与hibernate集成 <bean id="sessionFactory" class="org.springframework.orm.hibernate3 ...

  6. js数据类型简单介绍

    JS数据类型 ECMAScript中有5种简单的数据类型:Undefined,Null,Boolean,Number,String.还有一种复杂的数据类型--Object(本质上是由一组无序的名值对组 ...

  7. 汉字与区位码互转(天天使用Delphi的String存储的是内码,Windows记事本存储的文件也是内码),几个常见汉字的各种编码,utf8与unicode的编码在线查询,附有读书笔记 good

    汉=BABA(内码)=-A0A0=2626(区位码)字=D7D6(内码)=-A0A0=5554(区位码) 各种编码查询表:http://bm.kdd.cc/ 汉(记住它,以后碰到内存里的数值,就会有敏 ...

  8. android adb源码分析(5)【转】

    本文转载自:http://blog.csdn.net/xgbing/article/details/52096880 本篇以“adb devices"命令为例,跟踪代码的执行流程. (1) ...

  9. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  10. 管理 Word 博客账户

    1.1 多个博客账户 笔者的电脑上,Word 2013 有多个博客账户,如下图所示: 图1.1 多个博客账户 这些账户的名称在 Word 里是自动生成的,无法更改.账户一多就无法与相应的网站一一对应, ...