题目传送门

 /*
题意:给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. ajax的异步操作及页面重定向跳转

    今天主要分享一个简单的ajax的异步操作数据,用javascript也有一段时间了,刚开始看到一些页面在没有页面刷新的情况下就可以实现数据的保存或者获取,觉得挺不可思议的,感觉速度很快,做了几个项目之 ...

  2. 火焰灯menu修改之后,可以实现数遍点击小方块停留在当前页面

    下载地址:http://www.cnblogs.com/RightDear/admin/Files.aspx 调用方式,传入一个参数 首页传入0,关于联盟传入1,产品展示传入2,依此类推 <sc ...

  3. R学习-- 数组和矩阵

    生成 4行5列的数组,逐列逐行赋值x = array(1:20, dim= c(4,5)) 依据已知向量生成二维数组i = array(c(1:3,3:1,4:6,5:7), dim=c(3,4))也 ...

  4. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  5. Spring boot 使用Junt

    //@RunWith:启动器,SpringJUnit4ClassRunner:Spring整合JUnit4 //@SpringBootTest获取启动类,相当于@Contextconfiguartio ...

  6. C.Candy

    There are NN children standing in a line. Each child is assigned a rating value. You are giving cand ...

  7. chmod更改文件的权限

    #include "apue.h" int main(int argc,char *argv[]) { struct stat stabuf; ) err_sys("st ...

  8. Apostrophe not preceded by \

    编辑strings.xml的时候, <string name="start">Let's get started!</string> 报错说:“Apostr ...

  9. [yii]Fetch data from database and create listbox in yii

    <?php $records = User::model()->findAll(); $list = CHtml::listData($records, 'id', 'username') ...

  10. 廖雪峰python3练习题一

    数据类型和变量 题目: 答案: print(123) print(456.789) print('\'Hello,world\'') print('\'Hello,\\\'Adam\\\'\'') p ...