CodeForces 525C Ilya and Sticks 贪心
题目: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 贪心的更多相关文章
- 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) C. Ilya and Sticks
题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...
- C. Ilya and Sticks
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 1270: Wooden Sticks [贪心]
点击打开链接 1270: Wooden Sticks [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 31 解决: 11 统计 题目描述 Lialosiu要制作木棍,给n根作为原料 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- C - Ilya and Sticks(贪心)
Problem description In the evening, after the contest Ilya was bored, and he really felt like maximi ...
- Codeforces 1119E Pavel and Triangles (贪心)
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...
随机推荐
- Android 调用webservice faultactor 错误
1.错误:02-05 09:56:17.266: E/WebServiceUtil(801): --- 内部异常堆栈跟踪的结尾 ---' faultactor: 'null' detail: org. ...
- python的reduce()函数
reduce()函数也是Python内置的一个高阶函数. reduce()函数接收的参数和 map()类似,一个函数 f,一个list,但行为和 map()不同,reduce()传入的函数 f 必须接 ...
- [LeetCode]题解(python):084-Largest Rectangle in Histogram
题目来源: https://leetcode.com/problems/largest-rectangle-in-histogram/ 题意分析: 给定一个数组,数组的数字代表这个位置上的bar的高度 ...
- nrf51 官方PWM库
地址:https://github.com/NordicSemiconductor/nrf51-pwm-library nrf_pwm_init函数 初始化PWM参数 设置输出pwm的gpio pin ...
- SSL握手流程
一.SSL是什么? 安全套接字(SSL)协议是Web浏览器和Web服务器之间安全交换信息的协议. SSL介于应用层和TCP层之间,应用层数据不再直接传递给传输层,而是传递给SSL层,SSL层对从应用层 ...
- 批量删除Kindle library 中的不想要的书籍
这是一个书签形式的脚本 有全选 批量删除什么的 亚马逊本身的删除太麻烦了 网上转的 原帖在这里http://tieba.baidu.com/p/2249582757 改进版本http://t ...
- 转: markdown基本语法
Markdown 是一种轻量级标记语言,能将文本换成有效的XHTML(或者HTML)文档,它的目标是实现易读易写,成为一种适用于网络的书写语言. Markdown 语法简洁明了,易于掌握,所以用它来写 ...
- QT4/QT5设置界面风格(QT4支持更多的Windows界面风格)
#include "mainwindow.h" #include <QApplication> #include <QTextCodec> #include ...
- linux 的 ping 原理
ping命令的工作原理是: ping命令是用来查看网络上另一个主机系统的网络连接是否正常的一个工具. 他向网络上的另一个主机系统发送ICMP报文,如果指定系统得到了报文,它将把报文原样传回给发送者,这 ...
- DOC下编译和运行带有包的java类文件
前言: 带有包名的java类在DOC下编译可以成功,但是运行出错 错误: 找不到或无法加载主类 com.soanl.socket.MyServer D盘temp文件下有个Hello.java文件,包 ...