Codeforces Round #428 (Div. 2)(A+B)

本文介绍了两道编程题目,一是关于如何最小化天数来分配一定数量的糖果,二是关于如何合理安排不同军团士兵的座位避免相邻。文章通过具体示例解析了问题,并提供了源代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Arya and Bran
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.

At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don’t give him the candies at the same day, they are saved for her and she can give them to him later.

Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).

Print -1 if she can’t give him k candies during n given days.

Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).

The second line contains n integers a1, a2, a3, …, an (1 ≤ ai ≤ 100).

Output
If it is impossible for Arya to give Bran k candies within n days, print -1.

Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.

Examples
input
2 3
1 2
output
2
input
3 17
10 10 10
output
3
input
1 9
10
output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.

In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.

In the third sample, Arya can’t give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
题意:每天会收到ai颗糖果,每天至多分出去8颗,问最少多少天可以分出去k颗。
代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#define NI  freopen("in.txt","r",stdin);
#define NO  freopen("out.txt","w",stdout);
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
const int NL=2550;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
int n,k;
int a[N];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        tot+=a[i];
        if(tot<8)
        {
            k-=tot;
            tot=0;
        }
        else
        {
            k-=8;
            tot-=8;
        }
        if(k<=0)
        {
            return 0*printf("%d\n",i);
        }
    }
    return 0*printf("-1\n");
}

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 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 n rows, 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行座位,k个军团的人,不同军团的人座位不能相邻,问能否坐下。
题解:真是烦,很明显可以将座位分成两种,双人座和4人座,3人或4人坐4人座,1人或2人坐双人座。注意4人座可以坐一个2和一个1,(3,4,6),一个2可以拆成两个1。然后分情况讨论就行了。
代码:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<map>
#define NI  freopen("in.txt","r",stdin);
#define NO  freopen("out.txt","w",stdout);
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
const int NL=2550;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
int n,k;
int a[N];
int main()
{
    cin>>n>>k;
     int tot=n*2;
    int cnt=n;
    for(int i=1; i<=k; i++)
    {
         cin>>a[i];
         cnt-=a[i]/4;
         a[i]%=4;
    }
    sort(a+1,a+1+k);
    reverse(a+1,a+1+k);
    int fl=0;
    int fr=0;
    for(int i=1; i<=k; i++)
    {
        if(a[i]==3)
        {
            cnt--;
        }
        else if(a[i]>0)
        {
            tot--;
            if(tot<0)
            {
            if(a[i]==1) fl++;
            if(a[i]==2) fr++;
            }
        }
    }
    int mx=max(fl,fr);
    int mi=min(fl,fr);
    if((cnt<0&&(tot/2)+cnt>=0)||(tot<0&&cnt-(mi+ceil((fl-mi)/2.0)+(fr-mi)/3*2+(fr-mi)%3)>=0)||(cnt>=0&&tot>=0))
        puts("YES");
    else
        puts("NO");
}
内容概要:本文档为《400_IB Specification Vol 2-Release-2.0-Final-2025-07-31.pdf》,主要描述了InfiniBand架构2.0版本的物理层规范。文档详细规定了链路初始化、配置与训练流程,包括但不限于传输序列(TS1、TS2、TS3)、链路去偏斜、波特率、前向纠错(FEC)支持、链路速度协商及扩展速度选项等。此外,还介绍了链路状态机的不同状态(如禁用、轮询、配置等),以及各状态下应遵循的规则和命令。针对不同数据速率(从SDR到XDR)的链路格式化规则也有详细说明,确保数据包格式和控制符号在多条物理通道上的一致性和正确性。文档还涵盖了链路性能监控和错误检测机制。 适用人群:适用于从事网络硬件设计、开发及维护的技术人员,尤其是那些需要深入了解InfiniBand物理层细节的专业人士。 使用场景及目标:① 设计和实现支持多种数据速率和编码方式的InfiniBand设备;② 开发链路初始化和训练算法,确保链路两端设备能够正确配置并优化通信质量;③ 实现链路性能监控和错误检测,提高系统的可靠性和稳定性。 其他说明:本文档属于InfiniBand贸易协会所有,为专有信息,仅供内部参考和技术交流使用。文档内容详尽,对于理解和实施InfiniBand接口具有重要指导意义。读者应结合相关背景资料进行学习,以确保正确理解和应用规范中的各项技术要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值