CodeForces 525C Ilya and Sticks 贪心
生活随笔
收集整理的這篇文章主要介紹了
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; }轉載于:https://www.cnblogs.com/TaoTaoCome/p/4701349.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的CodeForces 525C Ilya and Sticks 贪心的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ALG.EXE是什么
- 下一篇: Atom飞行手册翻译: 3.7 调试