BZOJ 4291: [PA2015]Kieszonkowe 水题
生活随笔
收集整理的這篇文章主要介紹了
BZOJ 4291: [PA2015]Kieszonkowe 水题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
4291: [PA2015]Kieszonkowe
Time Limit: 1 Sec ?
Memory Limit: 256 MB
題目連接
http://www.lydsy.com/JudgeOnline/problem.php?id=4291Description
給定n個數,請從中選出若干個數,使得總和為偶數,請最大化這個總和。Input
第一行包含一個正整數n(1<=n<=1000000)。 第二行包含n個正整數a_1,a_2,...,a_n(1<=a_i<=1000)。Output
輸出一個正整數,即最大的總和,若無解則輸出NIESTETY。Sample Input
52 4 3 3 3
Sample Output
12?
HINT
?
題意
?
題解:
無解情況只有一種,那么n=1,a[1]%2==1
有解的話,全部加起來,如果是偶數的話就直接輸出
否則就刪去一個最小的奇數就好了
代碼:
#include<stdio.h> #include<algorithm> using namespace std; int a[1000005]; int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);if(n==1){if(a[1]%2==1)printf("NIESTETY\n");elseprintf("%d\n",a[1]);}else{sort(a+1,a+n+1);long long sum = 0;for(int i=1;i<=n;i++)sum = sum + a[i];if(sum % 2 == 0){printf("%lld\n",sum);return 0;}for(int i=1;i<=n;i++){if(a[i]%2==1){printf("%lld\n",sum-a[i]);return 0;}}} }?
轉載于:https://www.cnblogs.com/qscqesze/p/4859918.html
總結
以上是生活随笔為你收集整理的BZOJ 4291: [PA2015]Kieszonkowe 水题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 10.5做题——全排列(初赛复习)
- 下一篇: jquery ajax json 数据的