Codeforces 525C. Ilya and Sticks
来源:互联网 发布:制作mod的软件 编辑:程序博客网 时间:2024/05/16 10:42
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths a1, a2, a3 and a4 can make a rectangle if the following properties are observed:
- a1 ≤ a2 ≤ a3 ≤ a4
- a1 = a2
- a3 = a4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks?
The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks.
The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks.
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
42 4 4 2
8
42 2 3 5
0
4100003 100004 100005 100006
10000800015
恩,题意是说,相当于是给出一系列长度的木棍,分别用4个木棍组成长方形,这里存在一种操作即将木棍的长度减1 问最终可组成的长方体的面积和。开始以为是求可组成的面积最大的长方体的面积。。。英语是硬伤
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define maxn 100010using namespace std;int r[5];int num[maxn];int main(){ int n; __int64 ans; while(~scanf("%d",&n)) { ans=0; for(int i=0;i<n;++i) scanf("%d",&num[i]); sort(num,num+n); int k=0; memset(r,0,sizeof(r)); for(int i=n-1;i>=0;--i) { if(num[i]-num[i-1]<=1) { r[k]=r[k+1]=num[i-1]; k+=2; i--; } if(k>=4) { ans+=(__int64)r[0]*r[2]; k=0; } } printf("%I64d\n",ans); } return 0;}
- codeforces 525C Ilya and Sticks
- CodeForces-525C Ilya and Sticks
- Codeforces 525C:Ilya and Sticks
- CodeForces 525C Ilya and Sticks
- Codeforces 525C. Ilya and Sticks
- Codeforces 525C Ilya and Sticks 【数学】
- Codeforces 525C Ilya and Sticks
- CodeForces 525C . Ilya and Sticks
- Codeforces 525C Ilya and Sticks【贪心】
- codeforces 525C Ilya and Sticks(简单贪心)
- CF 525C(Ilya and Sticks-贪心)
- CF 525 C. Ilya and Sticks
- Code Forces 525C Ilya and Sticks
- Codeforces Round #297 (Div. 2) C.Ilya and Sticks
- C. Ilya and Sticks(Codeforces Round 297(div2))
- 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
- Ajax 请求返回 html 页面并展示
- (一)C++语言中类对象的本质
- 51nod 1022 石子归并 环形+四边形优化
- arm9+linux fl2440 GPRS SIM卡 模块 ppp拨号上网
- RESTFUL API 安全设计指南
- Codeforces 525C. Ilya and Sticks
- Golang把所有包括底层类库,输出到stderr的内容, 重新定向到一个日志文件里面?
- java--ArrayList去除集合中字符串的重复值
- 链队列的实现
- JavaScript ECMAScript5
- Quartz时间配置规则
- 特殊的算术操作指令详解
- 面试算法题
- 构建之法学习心得3:源代码的合作