Codeforces839B Game of the Rows

用Coze平台30分钟打造《花光10亿》小游戏:零代码AI开发实战 本文详细介绍了如何利用字节跳动推出的Coze平台,在30分钟内零代码开发一款名为《花光10亿》的AI小游戏。通过配置提示词、集成图像生成插件、构建自动化工作流以及使用数据库功能,即使没有编程基础的用户也能快速将创意转化为可交互的智能应用,体验AI开发的便捷与高效。 阅读详情
B. Game of the Rows
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has nrows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.

A row in the airplane

Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.

Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.

Input

The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.

The second line contains k integers a1, a2, a3, ..., ak (1 ≤ ai ≤ 10000), where ai denotes the number of soldiers in the i-th group.

It is guaranteed that a1 + a2 + ... + ak ≤ 8·n.

Output

If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
2 2
5 8
output
YES
input
1 2
7 1
output
NO
input
1 2
4 4
output
YES
input
1 4
2 2 1 2
output
YES
Note

In the first sample, Daenerys can place the soldiers like in the figure below:

In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.

In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.

In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).

———————————————————————————————————

题目的意思是给出n排座位,和m组人数信息,要求不同组的不能相邻坐

思路:贪心先4个排,多出来的4人坐拆成2人座和1人座,剩下的2个排,最后判断剩下

的人剩下的座位是否足够,维护人数时可以用优先队列维护

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
#define mod 10000007
#define mem(a,b) memset(a,b,sizeof a)



int main()
{
    int n,m,a;
    while(~scanf("%d%d",&n,&m))
    {
        priority_queue<int>q;
        while(!q.empty())
            q.pop();
        for(int i=0; i<m; i++)
        {
            scanf("%d",&a);
            q.push(a);
        }
        int cnt=0;
        while(cnt<n&&!q.empty())
        {
            if(q.top()<4)
                break;
            int f=q.top();
            q.pop();
            if(f/4+cnt<=n)
            {
                cnt+=f/4;
                f%=4;
                if(f>0) q.push(f);
            }
            else
            {
                f-=4*(n-cnt);
                cnt=n;
                q.push(f);
            }
        }

        int x=2*n+n-cnt;
        int y=0;
        while(y<x&&!q.empty())
        {
            if(q.top()<2)
                break;
            int f=q.top();
            q.pop();
            if(f/2+y<=x)
            {
                y+=f/2;
                f%=2;
                if(f>0) q.push(f);
            }
            else
            {
                f-=2*(x-y);
                y=x;
                q.push(f);
            }
        }
        int ss=x-y+n-cnt;
        int xx=0;
        while(!q.empty())
        {
            xx+=q.top();
            q.pop();
        }
        if(xx<=ss)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


GEO数据挖掘实战:用R语言从GSE42872数据集中找到关键差异基因(附完整代码) 本文详细介绍了使用R语言从GSE42872数据集中挖掘关键差异基因的完整流程,包括数据下载、探针ID转换、差异表达分析和功能富集分析。通过实战代码演示,帮助生信研究者掌握GEO数据挖掘的核心技术,快速识别疾病相关基因并理解其生物学功能。 阅读详情

相关推荐

基于 SpringAI 整合 DeepSeek 模型实现 AI 聊天对话

很多云平台都提供了一键部署大模型的功能,这里不再赘述(阿里云百炼平台、火山方舟-火山引擎等)Ollama。

📜一个热爱探索的人 1287

codeforces 839 B Game of the Rows

B. Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Daenerys Targaryen has an army consisting of k gro

Qian998的博客 941

经典烧脑算法逻辑题--高楼扔鸡蛋:最少次数测出鸡蛋摔碎临界点。

如果在第2层没碎,换到第3层扔.......如果第59层没碎,换到第60层扔;有2个鸡蛋,从100层楼上往下扔,以此来测试鸡蛋的硬度。比如鸡蛋在第9层没有摔碎,在第10层摔碎了,那么鸡蛋不会摔碎的临界点就是9层。因此,我们尝试每10层扔一次,第一次从10层扔,第二次从20层扔,第三次从30层......一直扔到100层。如果第一枚鸡蛋,在50层碎了,第二枚鸡蛋,就从第1层开始扔,一层一层增长,一直扔到第49层。如果第一枚鸡蛋在50层没碎了,则继续使用二分法,在剩余楼层的一半(75层)往下扔。

借雨醉东风的博客 1832

Codeforce 839 -- B Game of the Rows 【思维 + 贪心】

传送门 //比赛的时候看错题了, 以为是相邻的座位要是不同的组来做, 关键是这样想还都能过样例. mmm. //下来就把它补了. 既然要相邻的座位要是同一组的人做. 那么就只有4+2+1的做法. 所以我们就把数都分解成这种形式就OK了, (注意34也是算挨着的), 还要注意在算下一种做法时要加上之前的做法, 比如做2的时候, 要把剩余做4的再加上, 因为4的不能连续做两个的, 所以直接加上就好

Anxdada -- 我等风来也等你 795

第4章 Stata参数检验

目录 4.1单一样本T检验 案例延伸 4.2独立样本T检验 案例延伸 1.改变置信水平 2.在异方差假定条件下进行假设检验 4.3配对样本T检验 案例延伸 1.改变置信水平 4.4单一样本方差的假设检验 案例延伸 4.5双样本方差的假设检验 参数检验(Parameter Test)是指对参数的平均值、方差、比率等特征进行的统计检验。参数检验一般假设统计总体的具体分布为已知,但是其中一些参数或者取值范围不确定,分析的主要目的是估计这些未知参数的取值,或者对这些参数进...

qq_45112156的博客 1万+

FLUENT UDF编译及蒸发冷凝相关问题

蒸发冷凝与相间传质

weixin_48029137的博客 1万+

codeforces839B(88/600)

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a

NineFailure的博客 713

Sigrity System Explorer Transient Analysis模式进行瞬态仿真分析操作指导-单端信号

Sigrity System Explorer Transient Analysis模式可以用于瞬态仿真分析,通过搭建简易拓扑用于前仿真分析通道的时域性能,下面搭建一个简易的单端拓扑进行说明,以下图为例,准备好发送接收端的IBIS模型, (ibis_se.ibs,本例发送接收端都使用相同的IBIS模型),以及传输线的S参数模型(welement_se.sp)最上方的图形界面是传输线的模型,本例是一个上下都有参考平面的带状线,右侧的梯形是蚀刻角度,根据W1和W2以及铜厚来确定。

weixin_54787054的博客 424

B - Game of the Rows

B. Game of the Rows time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Daenerys Targaryen has an army consisting of k groups of soldiers, the

樱花满地集于我心,楪舞纷飞祈愿相随 604

CONN工具箱分析fmri数据笔记1

前言一、安装二、预处理三、去噪 前言 CONN:functional connectivity toolbox,是基于MATLAB和SPM的一个对功能磁共振数据进行分析的一个工具箱。可以进行以下分析: Seed-based correlations (SBC), ROI-to-ROI correlations, graph analyses, Independent component analyses(group-ICA), Masked (ICA) Amplitude of Low-Frequency.

weixin_52073820的博客 6588

大语言模型应用指南:幻觉和偏见问题

大语言模型应用指南:幻觉和偏见问题 1. 背景介绍 1.1 大语言模型的发展历程 1.1.1 早期的语言模型 1.1.2 Tr

AI天才研究院 964

B. Game of the Rows

B. Game of the Rows time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Daenerys Targaryen has an army consi...

weixin_34244102的博客 141

22、预条件技术:矩阵分解与多项式预条件器

本文系统介绍了预条件技术中的不完全分裂法、多项式预条件器和近似逆预条件器。内容涵盖矩阵分解的基本原理、不完全LU和Cholesky分解的实现方法、基于填充水平和阈值策略的改进技术,以及多项式和近似逆预条件器的数学基础与应用。通过算法流程图和表格对比,展示了各类预条件器的适用场景与优缺点,同时探讨了其在迭代求解中的关键作用和未来发展方向。

theta的博客 98

Codeforces 839B Game of the Rows 贪心

传送门:Codeforces 839B 题意:有k个小队坐飞机,每个小队有a[i]人,飞机上有n排座位,每排座位有8个,定义同一排中{1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.   几个座位是相邻的,问能否保证相邻的座位中没有两个不同的队伍的人。 思路:先贪心的使用3、4、5、6四个座位,然后再用两边的,我是用优先队列维护的这一过程,比赛的时候傻X的一

WA是一笔财富 369

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

codeforces 839b 之 Game of the Rows

B. Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Daenerys Targaryen has an army consistin

ESESZB的博客 511

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

CodeForces - 839B Game of the Rows

B. Game of the Rowstime limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutput standard outputDaenerys Targaryen has an army consisting of k groups of soldiers, the i-th

以梦为马,不日抵达。 244

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【CodeForces - 839B Game of the Rows】 贪心

B. Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Daenerys Targaryen has an army consistin

于心有愧丶 402

Codeforces 839B-Game of the Rows

Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Daenerys Targaryen has an army consisting o

wang_128的博客 545

CodeForces 839B Game of the Rows

写的有点丑,,,#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<set> #include<stack> #include<queue> #include<ctype.h> #include<vector> #include<algorithm> // c

床前明月光 327

Game of the Rows(Codeforces-839B)

B. Game of the Rows time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th...

lvy_yu_ET的博客 253

CodeForces 839B. Game of the Rows 贪心

题目传送门 注意点:2 7 2 2 2 2 2 2 2这个样例的排列可以是下图这种形式,结果是YES。我就是被这个点卡了好几个小时。 AA BBOC DD EE FFOC GG #include using namespace std; int main() { int n,k,x; cin >> n >> k; int sum2 = n*2,sum4

三生锁链 257

Codeforces 839B - Game of the Rows

839B - Game of the Rows 思路:先放4个的,然后再放2个的,最后再放1个的。 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) ...

weixin_33910137的博客 113

Restaurant Tables【CodeForces 828A】+Game of the Rows【CodeForces 839B】

感觉这两个题很像,解法相同。 Restaurant Tables 题意:给顾客安排座位,如果顾客是一个人,就安排一个位置的,如果没有就安排两个座位的,但只占一个位置。顾客是两个人就安排两个位置。 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #def...

快速乘与快速幂 415

Talon声音编程实战指南:从安装配置到代码生成

声音编程(Voice Coding)是一种将语音转化为精准、低延迟、本地化操作指令的人机交互范式,其核心在于绕过云端理解,直接映射为操作系统级动作。它依托本地语音识别引擎(如优化版Whisper)、可编程动作层(Python脚本)与轻量运行时(Rust实现),实现毫秒级响应和隐私可控。相比通用语音助手,声音编程强调确定性执行而非模糊问答,技术价值体现在消除重复性劳损(RSI)、提升开发者上下文连续性,并支撑终端控制、编辑器导航、本地LLM代码生成等工程场景。本文聚焦Talon这一开源事实标准,系统拆解其安装

weixin_33919950的博客 340

Game of the Rows CodeForces - 839B

Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recen

白黑菜的博客 457

Codeforces 839B Game of the Rows (贪心)

题目链接CF 839B题目大意有kk组人,第ii组有aia_i个人。飞机上有nn排座位,每排座位如下图: 问是否存在一种就座方案,使得不存在不同组的人坐在相邻的位置。分析这是Round #428 (Div.2)的B题,当时比赛的时候是通过的,赛后被Hack掉了(新增数据见注释)。。。自己想的情况还是不够全面。 显然这是一道贪心题。 首先我们尽可能的让同一组的4个人去坐四人座 然后尽可能让同一

歪歪T的拿金之路 392
上一篇: Codeforces839A Arya and Bran
下一篇: Codeforces839C Journey
Jelly_acm
博客等级 码龄11年 89粉丝 421原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值