HDU 5835 Danganronpa【贪心】

10 篇文章 0 订阅

Danganronpa

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 550    Accepted Submission(s): 398


Problem Description
Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of  n  kinds with  a[i]  quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students' desks are in a row. Chiaki Nanami wants to arrange gifts like this:

1. Each table will be prepared for a mysterious gift and an ordinary gift.

2. In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.

3. There are no limits for the mysterious gift.

4. The gift must be placed continuously.

She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren't you?
 

Input
The first line of input contains an integer  T(T10)  indicating the number of test cases.

Each case contains one integer  n . The next line contains  n   (1n10)  numbers:  a1,a2,...,an (1ai100000) .
 

Output
For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami's question.
 

Sample Input
  
  
1 2 3 2
 

Sample Output
  
  
Case #1: 2
 

Author
UESTC
 

Source
 


①找规律
首先每种情况的最大答案就是SUM/2。
下面就判断能不能达到SUM/2,如果某种礼物的数量远远超过了其余种类的数量和那么就不能达到,
这里,我先将所有礼物sort了一下,从小到大排序,把前n-1种礼物数量加起来,记为sum1,如果
sum1>=sum/2/2,那么就可以达到最大答案sum/2,否则答案是:sum1*2+1。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
typedef long long LL;
const int INF =0x7FFFFFFF;

const int M=1e5+1;
int num[M];
int i,j,k,n,t,sum,sum1;

int main()
{
    scanf("%d",&t);
    rep(k,1,t+1)
    {
        sum=0;sum1=0;
        scanf("%d",&n);
        rep(i,0,n){
            scanf("%d",&num[i]);
            sum+=num[i];
        }
        sort(num,num+n);
        rep(i,0,n-1){
           sum1+=num[i];
        }
        if(sum1>=sum/2/2)
            printf("Case #%d: %d\n",k,sum/2);
        else printf("Case #%d: %d\n",k,sum1*2+1);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值