#423

news/2023/11/28 8:06:04

第一次参加CF比赛T^T真是惊险刺激啊!大佬太多了!!!膜拜大佬!

A. Restaurant Tables
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a small restaurant there are a tables for one person and b tables for two persons.

It it known that n groups of people come today, each consisting of one or two people.

If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.

If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.

You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.

Input

The first line contains three integers na and b (1 ≤ n ≤ 2·1051 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.

The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.

Output

Print the total number of people the restaurant denies service to.

Examples
input
4 1 2
1 2 1 1
output
0
input
4 1 1
1 1 2 1
output
2
Note

In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.

In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.



//一开始没用c记录两座已有一个人坐了的,然后就……

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{int n, a, b, c,num, ans = 0;scanf("%d %d %d",&n, &a, &b);c = b;while(n--){scanf("%d",&num);if(num == 2){if(b > 0 && c > 0){b--;c--;}	elseans += 2;}else if(num == 1){if(a > 0)a--;else if(b > 0){b --;}else if(c > 0){c--;}else ans++;}}printf("%d\n",ans);
} 




B. Black Square
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.

You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.

The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

Output

Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

Examples
input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
output
5
input
1 2
BB
output
-1
input
3 3
WWW
WWW
WWW
output
1
Note

In the first example it is needed to paint 5 cells — (2, 2)(2, 3)(3, 2)(3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).

In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.

In the third example all cells are colored white, so it's sufficient to color any cell black.


//分析:特殊情况要分清楚,黑色细胞数确定, 只需确定构成正方形的最小边长

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{int n, m, i, j, right = 0, left = INF, up = INF, down = 0, sum = 0, ans = 0, flag = 1;char ch, space;scanf("%d %d", &n, &m);space = getchar();for(i = 0; i < n; ++i){for(j = 0; j < m ; ++j){ch = getchar();if(ch == 'B'){sum++;right = max(right, j);left = min(left, j);up = min(up, i);down = max(down, i);}else{flag = 0;}}space = getchar();}if(flag){if(n == m)printf("0\n");elseprintf("-1\n");}else if(sum <= 0){printf("1\n");}else if(!flag && sum){ans = max((right - left + 1), (down - up + 1));if(ans > n || ans > m)printf("-1\n");else{printf("%d\n",(ans*ans) - sum);}}} 

//待补充



http://www.ppmy.cn/news/271344.html

相关文章

Day435436.支付系统 -谷粒商城

支付系统 一、基本概念 1、加密 ①对称加密 什么是对称加密 所谓对称加密&#xff0c;就是发送方要给接收方在网络上发送一段明文&#xff0c;但是不能直接发。 发送方需要加密&#xff0c;对称加密指的就是加密和解密用的是同一把密钥。 假设发送方准备了一串明文&#…

LeetCode-436. 寻找右区间【双指针】

题目描述&#xff1a; 给你一个区间数组 intervals &#xff0c;其中 intervals[i] [starti, endi] &#xff0c;且每个 starti 都 不同 。 区间 i 的 右侧区间 可以记作区间 j &#xff0c;并满足 startj > endi &#xff0c;且 startj 最小化 。 返回一个由每个区间 i…

439

1&#xff0e;政治   具体来说&#xff0c;政治共有六门课程需要复习&#xff0c;工作量大&#xff0c;任务较重。从历年考研试卷出题的情况看&#xff0c;六门课程在试卷中所占比重并不平均&#xff0c;所以我认为要根据各门课程的不同特点合理安排复习时间。 首先&#xf…

436分复试被刷!山东大学软件学院

山东大学是一所985大学&#xff0c;位于山东省省会济南市&#xff0c;计算机学科评估B&#xff0c;软件工程学科评估B&#xff0c;在985大学中排名中游&#xff0c;水平还不错。 今天来聊一下&#xff0c;山东大学软件学院的情况。 首先是2021考研的招生目录&#xff1a; 图片来…

【博客436】kubeadm init原理

kubeadm init原理 在k8s master中&#xff0c;会先启动一个kubelet&#xff0c;控制面组件通过kubelet static pod特性启动 初始化一个工作流执行如下阶段工作&#xff1a; 也可以使用 kubeadm init phase 分阶段执行 // cmd/kubeadm/app/cmd/init.go-NewCmdInit()...// initi…

LeetCode 436. 寻找右区间(二分查找)

1. 题目 给定一组区间&#xff0c;对于每一个区间 i&#xff0c;检查是否存在一个区间 j&#xff0c;它的起始点大于或等于区间 i 的终点&#xff0c;这可以称为 j 在 i 的“右侧”。 对于任何区间&#xff0c;你需要存储的满足条件的区间 j 的最小索引&#xff0c;这意味着区…

436. 寻找右区间

给定一组区间&#xff0c;对于每一个区间 i&#xff0c;检查是否存在一个区间 j&#xff0c;它的起始点大于或等于区间 i 的终点&#xff0c;这可以称为 j 在 i 的“右侧”。 对于任何区间&#xff0c;你需要存储的满足条件的区间 j 的最小索引&#xff0c;这意味着区间 j 有最…

63

该系列文档是本人在学习 Mybatis 的源码过程中总结下来的&#xff0c;可能对读者不太友好&#xff0c;请结合我的源码注释&#xff08;Mybatis源码分析 GitHub 地址、Mybatis-Spring 源码分析 GitHub 地址、Spring-Boot-Starter 源码分析 GitHub 地址&#xff09;进行阅读 MyB…

Java实现 LeetCode 436 寻找右区间

436. 寻找右区间 给定一组区间&#xff0c;对于每一个区间 i&#xff0c;检查是否存在一个区间 j&#xff0c;它的起始点大于或等于区间 i 的终点&#xff0c;这可以称为 j 在 i 的“右侧”。 对于任何区间&#xff0c;你需要存储的满足条件的区间 j 的最小索引&#xff0c;这…

LeetCode 436 python 哈希表

哈希表扫描 题解&#xff1a;因为测试实例的长度为2*10**4&#xff0c;因此&#xff0c;算法复杂度不能超过nlogn。 注意&#xff1a;题意是比较大于等于endi的最小startj&#xff0c;且i&#xff0c;j有可能相等 因为每个starti都不同&#xff0c;因此&#xff0c;为方便后续…

力扣(LeetCode)436. 寻找右区间(2023.03.10)

给你一个区间数组 intervals &#xff0c;其中 intervals[i] [starti, endi] &#xff0c;且每个 starti 都 不同 。 区间 i 的 右侧区间 可以记作区间 j &#xff0c;并满足 startj > endi &#xff0c;且 startj 最小化 。 返回一个由每个区间 i 的 右侧区间 在 interv…

443

443是一个用于建立安全的Hypertext Transfer Protocol (HTTP) 连接的端口号。它是一个标准的端口号&#xff0c;用于安全的Web浏览器和Web服务器之间的通信。通常&#xff0c;443端口被用来传输加密的数据&#xff0c;并且通过使用SSL/TLS协议来保护数据的完整性和保密性。 443…

LeetCode_二分搜索_中等_436.寻找右区间

目录 1.题目2.思路3.代码实现&#xff08;Java&#xff09; 1.题目 给你一个区间数组 intervals &#xff0c;其中 intervals[i] [starti, endi] &#xff0c;且每个 starti 都不同 。 区间 i 的右侧区间可以记作区间 j&#xff0c;并满足 startj > endi&#xff0c;且 s…

436-C++基础语法(71-80)

71、静态变量什么时候初始化&#xff1f; 初始化只有一次&#xff0c;但是可以多次赋值&#xff0c;在主程序之前&#xff0c;编译器已经为其分配好了内存&#xff1b;静态局部变量和全局变量一样&#xff0c;数据都存放在全局区域&#xff0c;所以在主程序之前&#xff0c;编…

红帽436——HA高可用集群之安装篇

红帽436——HA高可用集群的安装 图释&#xff1a; 1- su - &#xff1a;真实机切换至root用户 2- virt-manager &#xff1a;打开KVM管理工具 3- 从Desktop开启虚拟机&#xff1a;cla***oom&#xff08;充当服务器的作用&#xff09;和三台节点机 图释&#xff1a;在每台节点…

LeetCode 力扣官方题解 | 436. 寻找右区间

LeetCode 力扣官方题解 | 436. 寻找右区间 寻找右区间 题目描述 难易度&#xff1a;中等 给你一个区间数组 intervals &#xff0c;其中 intervals [i] [starti, endi] &#xff0c;且每个 starti 都 不同 。 区间 i 的 右侧区间 可以记作区间 j &#xff0c;并满足 star…

技巧:win10的另一种美化字体的方式,使用noMeiryoUI

目录 1. 前提2. 字体选择3. 查看已经安装的字体并查看效果4. 安装软件修改系统字体5. 修改浏览器字体 1. 前提 21年的时候写了一篇文章&#xff0c;《Windows10下美化字体&#xff0c;达到类似mac的效果》&#xff0c;当时还很迷恋macType这个软件的使用&#xff0c;觉得好牛逼…

某电机修造厂变电所一次系统设计

摘要 由于国内人民生活水平的提高&#xff0c;科技不断地进步&#xff0c;控制不断地完善&#xff0c;从而促使变电所设计技术在电气系统领域占据主导权&#xff0c;也使得110kV变电所被广泛应用。在变电所系统设计领域中&#xff0c;110kV变电所成为目前一处亮丽的风景线&…

酷睿i513400参数 i5 13400功耗 i5 13400属于什么水平档次级别

i5-13400 CPU 拥有 6 个大核和 4 个小核&#xff0c;共计 10 核 16 线程&#xff0c;主频 2.5 GHz&#xff0c;全核睿频可达 4.1 GHz&#xff0c;单核睿频 4.6 GHz&#xff0c;配备 28 MB 的 L3 缓存&#xff0c;基础功耗 65W。 i513400组装电脑怎么搭配更合适这些点很重要 htt…
最新文章