日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

發布時間:2025/4/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 MB
Submit: xxx? Solved: 2xx

題目連接

http://codeforces.com/contest/525/problem/C

Description

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, sticks 5?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?

Input

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.

Output

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.

Sample Input

Input 4
2 4 4 2 Input 4
2 2 3 5 Input 4
100003 100004 100005 100006

Sample Output

Output 8 Output 0 Output 10000800015

HINT

?

?

題意:

給你一堆棍子,然后選擇一些棍子來組成多個矩形,這些棍子有一個特點,長度為l的可以當成長度為l-1的用,問你最多能夠成的矩形總面積是多少!

總面積是多少!

總面積是多少!

唔,因為很重要,所以說三遍,喵~

題解:

用一個flag[l]記錄長度為l的棍子有多少個,flag1[l]記錄長度為l+1的棍子有多少個,然后從大往小掃,如果發現flag[l]+flag1[l]=>2的時候,那就把長度為l的當成一條邊,然后再i++再繼續掃一下這個長度,優先減flag1[l]的數量。

注意,當減flag[l]的時候,flag1[l-1]也會減少~

就這樣邊掃邊維護就好啦~

唔,我感覺我說的不是很清楚……

還是看我呆呆的代碼吧

~\(≧▽≦)/~啦啦啦,這道題完啦

代碼:

?

//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 4000100 #define mod 10007 #define eps 1e-9 //const int inf=0x7fffffff; //無限大 const int inf=0x3f3f3f3f; /**/ //************************************************************************************** inline ll read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } int flag[maxn]; int flag2[maxn]; map<int,int> s; int main() {int n;n=read();int m=0;for(int i=0;i<n;i++){int x=read();flag[x]++;flag2[x-1]++;m=max(m,x);}ll ans2=0;ll ans1=0;ll ans=0;for(int i=m;i>=0;i--){if(flag[i]+flag2[i]>=2){if(ans1==0){ans1=i;if(flag2[i]==0){flag[i]-=2;flag2[i-1]-=2;}else if(flag2[i]==1){flag2[i]-=1;flag[i]-=1;flag2[i-1]-=1;}elseflag2[i]-=2;}else{if(flag2[i]==0){flag[i]-=2;flag2[i-1]-=2;}else if(flag2[i]==1){flag2[i]-=1;flag[i]-=1;flag2[i-1]-=1;}elseflag2[i]-=2;ans+=ans1*i;ans1=0;}i++;}}cout<<ans<<endl;return 0; }

?

轉載于:https://www.cnblogs.com/qscqesze/p/4371809.html

總結

以上是生活随笔為你收集整理的Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 色一涩| 欧美精品第二页 | 国产视频一区在线播放 | 国产97自拍 | 亚洲欧美激情一区二区三区 | 成人高清 | 爆操91| 日韩在线视频免费 | 91午夜精品亚洲一区二区三区 | 欧美日本中文字幕 | 青青青青青操 | 视频在线看 | 亚洲av无码一区二区三区在线观看 | 亚洲国产黄色av | 超碰资源总站 | 日韩美女性生活 | 99热3| 国产精品久久久精品三级 | 久久国产精品无码一级毛片 | 免费高清欧美大片在线观看 | 国产福利99 | 久久少妇网 | 男人免费视频 | 日韩中文av | 麻豆网站在线看 | 黑帮大佬和我的365日第二部 | 一节黄色片 | 亚洲一区二区三区四 | 韩国电影大尺度在线观看 | 国产成人精品一区二区三区网站观看 | 香蕉婷婷| 色综合久久五月 | 日韩一区二区三区三四区视频在线观看 | 国产精品福利一区二区三区 | 狠狠干2022 | 自拍偷拍第1页 | 美女热逼 | 亚洲视频 欧美视频 | 奇米久久久 | 亚洲欧美中文字幕5发布 | 中文字幕第7页 | 亚洲欧美另类中文字幕 | 91尤物国产福利在线观看 | 狠狠人妻久久久久久综合麻豆 | 亚洲精品久久久狠狠狠爱 | 日日噜噜噜夜夜爽爽狠狠视频97 | 男人天堂中文字幕 | 国产高清av在线 | 亚洲一区二区播放 | 国产女人18水真多18精品一级做 | 欧美人一级淫片a免费播放 西方av在线 | 一级做a爱片久久 | 亚洲精品久久久中文字幕 | 国精产品一区二区 | 快播91| 欧美激情视频一区二区三区 | 亚洲a视频 | 国产小视频在线看 | 嫩草av91| 久久伊人精品 | 成人国产精品免费观看视频 | 一区二区三区久久久 | 婷婷六月网 | 国产 欧美 日韩 一区 | 操欧美女| 国产日韩欧美日韩大片 | 奇米网888 | 无码人妻精品一区二区三区66 | 青青草av在线播放 | 91精品国产高清一区二区三密臀 | 尤物精品视频在线观看 | 午夜激情av在线 | 日本在线不卡一区二区三区 | 99国产精品国产免费观看 | 老子午夜影院 | 亚洲av乱码久久精品蜜桃 | 久久精品影视 | 九色.com | 男女视频在线观看免费 | 免费日韩在线 | 成人av电影免费观看 | 男人视频网站 | 久久综合五月婷婷 | 韩国三级hd中文字幕的背景音乐 | 亚洲精品午夜精品 | www.爆操| 欧美激情第五页 | 超碰伊人网 | 亚洲午夜精品在线 | 日韩av不卡在线播放 | 欧美黑人性xxx猛交 少妇无套内谢久久久久 | 日本少妇网站 | 天天干网| 在线中文字幕一区 | 中文高清av | 99精品人妻少妇一区二区 | 日本少妇网站 | 国产欧美日韩免费 | 日本午夜小视频 |