贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
题目传送门
/*
题意:给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的更多相关文章
- 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 ...
- 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 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls
题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
随机推荐
- 12.怎样自学Struts2发送邮件和验证补充[视频]
12.怎样自学Struts2发送邮件和验证补充[视频] 之前写了一篇"打算做一个视频教程探讨怎样自学计算机相关的技术",优酷上传不了,仅仅好传到百度云上: http://pan.b ...
- rtsp 播放器
http://blog.csdn.net/niu_gao/article/details/7753672 /********************************************** ...
- java File文件操作共用方法整理
package org.jelly.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io ...
- python day- 7 进本数据类型的先关知识点 set集合 深浅拷贝
一.基本数据类型相关知识 1.str. join()函数 关于字符串 a = "我爱北京" b = a.join("真的") 将&q ...
- dotnet core 入门
之前一至用的dotnet 做开发,项目没有用过.netcore,现在看微软对dotnetcore的重视度越来越高,所以dotnetcore也是每一个.dotnet开发人员的一项必备技能.一个偶然的机会 ...
- springboot如何使用外部tomcat容器
一般情况spring-boot-starter-web是自带tomcat(即springboot内嵌tomcat),所以打包直接生成jar包,用java -jar命令就可以启动. 但,有时我们希望用w ...
- 更改NavigationView侧滑菜单文字颜色
NavigationView menu默认icon和title会随着菜单状态改变而改变,选择某个菜单后再次打开侧边菜单后会发现该菜单的icon和title会变成应用的主颜色,其他菜单项仍然为黑色. 如 ...
- poj 3461 Oulipo(kmp统计子串出现次数)
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...
- hdu 4398 Template Library Management(贪心+stl)
题意:n道题,每道题需要一个模板,现在手头有m个模板(标号1~m),解题的时候,如果没有需要的模板,可以向朋友借,但是用完之后必须在还给朋友一个模板(也就是说保持手头拥有m个模板),求解完n道题最少需 ...
- UI:KVO、KVC
什么是KVC 什么是 KVO ? KVC:(NSKey ValueCoding)”键-值 编码“是一种间接的访问对象属性(字符串表征)的机制.对象的属性都可以通过使用KVC机制用相同的方式访问.我们 ...