HDU 5835 Danganronpa

原题:

Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of nn kinds with a[i]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)T(T≤10) indicating the number of test cases. 

Each case contains one integer nn. The next line contains nn (1n10)(1≤n≤10) numbers: a1,a2,...,ana1,a2,...,an(1ai100000)(1≤ai≤100000).
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


题意:

       有n种礼物,每种有a[i]个,一些为神秘礼物,一些为普通礼物,将这些礼物排列,每一组必须要有一个神秘礼物和一个普通礼物,相邻的组普通礼物必须互不相同,最多可以排多少组。


思路:

      首先计算所有礼物每组一个相邻互不相同可以排多少组,可以得知,当数量最多的一种比其他所有种礼物数量加起来还要多1个以上时,则可以排(sum-a[max])*2+1组,其他情况则全部可以排成相邻互补相同,即sum组。

     当为第一种情况,即不能全部排完时,又分两种情况。1、当排列礼物数小于等于无法排列的礼物时,则可以把剩下的礼物当作神秘礼物分发到排列好的每一组去,则答案为(sum-a[max])*2+1。2、当排列礼物数小于等于无法排列的礼物时,则需要一部分排列的礼物和所有的无法排列的礼物为神秘礼物,则答案为sum/2。

    当为第二种情况时,则把一半的排列的礼物当作神秘礼物分发到前一半里,则答案为sum/2。


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <sstream>
#include <climits>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define pi acos(-1.0)
#define INF 2147483647
using namespace std;
typedef long long ll;
typedef pair <int,int > P;
const int maxn=100005;  
int a[maxn];
int n,i,j,t;
int main()
{
    scanf("%d",&t); 
    for(int k=1; k<=t; k++)
    {
        scanf("%d",&n);
        memset(a,0,sizeof(a));
        int sum=0;
        for(i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        sort(a,a+n,greater<int >() );
        sum-=a[0];
        if(a[0]-sum>1)
        {
            int ans1=sum*2+1;
            int ans2=sum+a[0]-ans1;
            if(ans1<=ans2)
                printf("Case #%d: %d\n",k,ans1);
            else
                printf("Case #%d: %d\n",k,(sum+a[0])/2);

        }
        else
        {
            int ans=sum+a[0];
            printf("Case #%d: %d\n",k,ans/2);
        }

    }
    return 0;
}


资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值