AtCoder Grand Contest 016 B - Colorful Hats

B - Colorful Hats


Time limit : 2sec / Memory limit : 256MB

Score : 700 points

Problem Statement

There are N cats. We number them from 1 through N.

Each of the cats wears a hat. Cat i says: "there are exactly ai different colors among the N−1 hats worn by the cats except me."

Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

Constraints

  • 2≤N≤105
  • 1≤aiN−1

Input

Input is given from Standard Input in the following format:

N
a1 a2  aN

Output

Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.


Sample Input 1

Copy
3
1 2 2

Sample Output 1

Copy
Yes

For example, if cat 12 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.


Sample Input 2

Copy
3
1 1 2

Sample Output 2

Copy
No

From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color. Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.


Sample Input 3

Copy
5
4 3 4 3 4

Sample Output 3

Copy
No

Sample Input 4

Copy
3
2 2 2

Sample Output 4

Copy
Yes

Sample Input 5

Copy
4
2 2 2 2

Sample Output 5

Copy
Yes

Sample Input 6

Copy
5
3 3 3 3 3

Sample Output 6

Copy
No

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const int maxn=1e6+10;
const int maxm=20;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int num[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        int minnum=inf,maxnum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&num[i]);
            minnum=min(minnum,num[i]);
            maxnum=max(maxnum,num[i]);
        }
        if(!(minnum+1==maxnum||minnum==maxnum))
        {
            printf("No\n");
            continue;
        }
        int color=maxnum;
        int maxc=0;
        for(int i=0;i<n;i++)
        {
            if(maxnum-1==num[i]) color--;
            else maxc++;
        }
        if(minnum+1==maxnum)
        {
            if(maxc>=color*2&&color>=1)
                printf("Yes\n");
            else printf("No\n");
        }
        else
        {
            if(maxc>=color*2||maxc==color+1)
                printf("Yes\n");
            else printf("No\n");
        }
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/mgz-/p/7081409.html

内容概要:本文档详细介绍了基于Cplex求解器的风光制氢合成氨系统优化研究,通过Matlab代码实现对这一复杂可再生能源系统的建模与优化分析。研究聚焦于风能、光伏等可再生能源耦合电解水制氢并进一步合成氨的综合能源系统,重点解决系统在容量配置与运行调度方面的协同优化问题。采用Cplex求解器进行高效的混合整数线性规划(MILP)求解,实现了对系统经济性、能效性、环境可持续性的多目标优化,涵盖设备选型与容量设计、能量流分配、运行策略制定、制氢与合成氨工艺集成等关键技术环节。该研究为高比例可再生能源消纳、绿氢规模化生产及绿色化工转型提供了重要的理论依据与可行的技术路径。; 适合人群:具备电力系统、能源系统、运筹学或化工过程系统工程等相关背景,熟悉Matlab编程与数学建模方法,从事新能源、氢能、综合能源系统、绿色化工等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 学习并复现高水平学术论文中关于风光制氢合成氨系统的优化模型构建方法;② 掌握利用Cplex求解器解决复杂能源系统混合整数线性规划(MILP)问题的核心技术与实践流程;③ 为自身的科研项目或工程应用提供系统建模、优化算法实现与代码参考的坚实基础。; 阅读建议:学习者应结合所提供的Matlab代码与相关参考文献,深入剖析模型的物理意义、数学推导过程、约束条件的设定逻辑以及目标函数的设计思路,特别关注Cplex与Matlab的接口调用与数据传递机制,并建议通过调整关键参数(如可再生能源出力、设备效率、成本系数等)进行敏感性分析,以全面理解系统优化的内在机理与决策影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值