题目传送门

 /*
题意:给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. 2016/05/25 抽象类与API(接口)差别

    简单来说, 接口是公开的,里面不能有私有的方法或变量,是用于让别人使用的,而抽象类是可以有私有方法或私有变量的, 另外,实现接口的一定要实现接口里定义的所有方法,而实现抽象类可以有选择地重写需要用到的 ...

  2. javascript event事件兼容性处理

    ie 6-8支持event事件,ff浏览器不支持 获取鼠标点击位置的坐标 document.onclick = function(){ alert(event.clientX +"-&quo ...

  3. 一个基本的spring+mybatis所需要的包

    spring+mybatis需要的包:org.springframework.spring-webmvc(spring框架DispatcherServlet需要,spring-webmvc会依赖spr ...

  4. HDU 5178 pairs —— 思维 + 二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)     ...

  5. download file by python in google colab

    https://stackoverflow.com/questions/15352668/download-and-decompress-gzipped-file-in-memory You need ...

  6. java24点算法

    输入任意的四个数,求出所有能得到二十四点的算式,不过我是菜鸟,可能性能方面不好,希望各位多多指教​1. [代码][Java]代码     import java.util.ArrayList;impo ...

  7. contents属性

    CALayer 有一个属性叫做contents,这个属性的类型被定义为id,意味着它可以是任何类型的对象.在这种情况下,你可以给contents属性赋任何值,你的app仍然能够编译通过.但是,在实践中 ...

  8. 一步一步学Silverlight 2系列(18):综合实例之RSS阅读器

    一步一步学Silverlight 2系列(18):综合实例之RSS阅读器   概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支 ...

  9. 前端CSS规范整理

    一.文件规范 1.文件均归档至约定的目录中. 具体要求通过豆瓣的CSS规范进行讲解: 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用U ...

  10. Vue.nextTick()的正确使用

    Vue异步执行DOM更新.只要观察导数据变化,Vue将开启一个队列,并缓冲在同一事件循环中发生的所有数据改变,如果同一个watcher被多次触发,只会一次推入到队列中.这种在缓冲时去除重复数据对于避免 ...