2019牛客暑期多校第六场题解ABDJ
A.Garbage Classification
题意:给你两个串,第一个串s由小写字母组成,第二个串t由dwh组成,长度为26,分别表示字母a到z代表的字符。现在要你判断:
- 如果字符串中‘h’的数量至少占s串长度的25%,输出 “Harmful”
- 如果字符串中‘h’的数量最多占s串长度的10%,输出 “Recyclable”
- 否则,如果字符串中‘d’的数量至少是‘w’的两倍,输出 “Dry”
- 否则输出 “Wet”
题解:判断即可。
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e3 + ;
char s[N],t[];
int main() {
int T, cnt = ;
for (scanf("%d",&T);T--;) {
scanf("%s%s",s,t);
int len = strlen(s);
printf("Case #%d: ", cnt++);
int num[] = {},w = , h = , d = ;
for (int i = ; i < len; i++) num[s[i]-'a']++;
for (int i = ; i < ; i++) {
if (t[i] == 'w') w+=num[i];
if (t[i] == 'h') h+=num[i];
if (t[i] == 'd') d+=num[i];
}
if (h* >= len) printf("Harmful\n");
else if (h* <= len) printf("Recyclable\n");
else if (d >= * w) printf("Dry\n");
else printf("Wet\n");
}
return ;
}
B.Shorten IPv6 Address
题意:给你一个128长度的二进制串,要转化成IPv6地址的形式,例如 “0:0:123:4567:89ab:0:0:0”(忽略前导0),若有连续两个及以上的0,那么可以把那一段写成“::”,但是注意一个地址中最多有1个“::”。要求输出最短的形式,如果长度相同输出字典序最小的结果。
题解:显然我们将最长连续0的那一段转化为“::”比转化把它短的要优,当有长度相同的连续0时,显然转化中间的比转化两边的优(转化中间的比转化两边的长度要少1),相同且都在首尾或者且都在中间时,显然选转化后面那个更优(‘0’字典序比‘:’小)。
可以将二进制转化为十六进制比较也可以转化为十进制比较,因为C++可以直接%x输出十六进制数所以用十进制比较方便。
想法是对的但是写丑了WA了一下午嘤嘤嘤(╥╯^╰╥)
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 2
const int N = 1e5 + ;
char s[];
int cel(int id) {
int x = ;
for (int i = id; i < id + ; i++) x = x * + s[i]-'';
return x;
}
int main() {
int T,t=;
for (scanf("%d",&T);T--;) {
scanf("%s",s);
int pos = -,num = ;
int a[] = {};
for (int i = ; i < ; i+=)
a[i/] = cel(i);
for (int i = ; i >= ; i--) {
int cnt = ;
if (!a[i]) {
while(i>= && !a[i]) i--,cnt++;
i++;
if (cnt == num && pos+num == && i) pos = i,num = cnt;
if (cnt > num) pos = i,num = cnt;
}
}
printf("Case #%d: ",t++);
for (int i = ; i < ; i++) {
if ( i == pos) {
if (pos == ) printf(":");
printf(":");
i+=num-;
}else {
printf("%x",a[i]);
if (i!=) printf(":");
}
}
printf("\n");
}
return ;
}
十进制
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 2
const int N = 1e5 + ;
char s[],ans[][];
bool _is0[];
char cel(int id) {
int x = ;
for (int i = id; i < id + ; i++) x = x * + s[i]-'';
if (x < ) return x+'';
return x-+'a';
}
bool judge0(int x){
int i;
for (i = ; ans[x][i+]; i++) {
if (ans[x][i] != '') return false;
for(int j = i; ans[x][j]; j++) ans[x][j] = ans[x][j+];
i--;
}
return ans[x][i]=='';
}
int main() {
int T,t=;
for (scanf("%d",&T);T--;) {
scanf("%s",s);
int pos = -;
int num = ;
for (int i = , j = ,k = ; i < ; i+=) {
ans[k][j++] = cel(i);
if(j == ) ans[k][j] = '\0',j = ,_is0[k]=judge0(k),k++;
}
for (int i = ; i >= ; i--) {
int cnt = ;
if (_is0[i]) {
while(i>= && _is0[i]) i--,cnt++;
i++;
if (cnt == num && pos+num == && i) pos = i,num = cnt;
if (cnt > num) pos = i,num = cnt;
}
}
printf("Case #%d: ",t++);
for (int i = ; i < ; i++) {
if ( i == pos) {
i+=num-;
if (pos == ) printf(":");
printf(":");
}else {
printf("%s",ans[i]);
if (i!=) printf(":");
}
}
printf("\n");
}
return ;
}
十六进制
D.Move
题意:有n件物品,每件物品体积为vi,用k个相同大小的盒子来装他们,问盒子最小体积可以为多少。
题解:我们知道盒子最小体积为max(a[n],sum/k),我们可以从最小可能的体积开始枚举,一个个来判断。数据都很小不超过1000所以不会T。
那我们怎么判断呢?我们可以把物品按体积由大到小依次放进盒子里,能放得下就放,否则就放下一个,放不进就表示盒子小了,否则就是答案。
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + ;
const ll INF = 1ll<<;
int a[N],n,m,b[N];
bool check(int x){
for (int i = ; i <= m; i++) b[i] = x;
for (int i = n; i >= ; i--) {
bool fg = ;
for (int j = ; j <= m; j++)
if (a[i] <= b[j]) {
b[j] -= a[i];
fg = ;
break;
}
if (!fg) return false;
}
return true;
}
int main() {
int T, cnt = ;
for (scanf("%d",&T);T--;) {
int sum = ;
scanf("%d%d",&n,&m);
for (int i = ; i <= n; i++) {
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a+,a++n);
for (int i = max(a[n],sum/m);;i++)
if (check(i)) {
printf("Case #%d: %d\n", cnt++,i);
break;
}
}
return ;
}
J.Upgrading Technology
题意:有n个技能,每个技能都有m个等级(一开始等级都为0),每升一级需要花费C(i,j)(只能一级一级升),如果每个技能都达到i级,可以得到di的利润。可以不升级利润为0,。问能得到的最大利润为多少。
题解:我们可以用前缀和维护每个技能升级的最小花费,倒着更新一遍最小值。然后把每个技能升级到i(可能是以上)所需的最小花费加起来,然后我们维护下每个等级利润d的前缀和,技能最小等级为i时的利润为d的前缀和 - 每个技能升级到i所需的最小花费。这里要注意两个点,一是我们前面维护的每个技能升级到i(可能是以上)所需的最小花费可能把技能等级更新到了i以上,若每个技能等级都在i以上,那么获得的利润就不是d1~i,而是当前最小技能j的利润和d1~j,所以我们需要保留一个升级到i所需花费与我们维护的最小值差最小的来确保最低等级为i且获得的利润最大。二是注意可能存在有技能等级为0,其他技能升级花费为负的情况。
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + ;
const ll INF = 1ll<<;
ll a[N][N],c[N][N],b[N];
int main() {
int T, cnt = ,n,m;
for (scanf("%d",&T);T--;) {
scanf("%d%d",&n,&m);
memset(a,,sizeof(a));
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
scanf("%lld",&a[i][j]);
a[i][j] += a[i][j-];
c[i][j] = a[i][j];
}
a[n+][m] += a[i][m];
for (int j = m-; j >= ; j--){
a[i][j] = min(a[i][j],a[i][j+]);
a[n+][j] += a[i][j];
}
}
b[] = ;
for (int i = ; i <= m; i++) {
scanf("%lld",&b[i]);
b[i] += b[i-];
}
ll ans = ;
for (int i = ; i <= m; i++) {
int pos = -;
ll mind = INF,d;
for (int j = ; j <= n; j++) {
d = c[j][i] - a[j][i];
if (d < mind) {
mind = d;
pos = j;
}
}
ans = max(ans,b[i]-a[n+][i]+a[pos][i]-c[pos][i]);
}
printf("Case #%d: %lld\n", cnt++,ans);
}
return ;
}
2019牛客暑期多校第六场题解ABDJ的更多相关文章
- 2019牛客暑期多校第五场题解ABGH
A.digits 2 传送门 题意:给你一个n,要求输出一个每一位数字之和能整除n且其本身也能整除n的数.n不超过100,要求的数不超过10000位数. 题解:直接将n输出n次. 代码: #inclu ...
- 2019 牛客暑期多校 第三场 F Planting Trees (单调队列+尺取)
题目:https://ac.nowcoder.com/acm/contest/883/F 题意:求一个矩阵最大面积,这个矩阵的要求是矩阵内最小值与最大值差值<=m 思路:首先我们仔细观察范围,我 ...
- 2019牛客暑期多校训练营(第二场) H-Second Large Rectangle(单调栈)
题意:给出由01组成的矩阵,求求全是1的次大子矩阵. 思路: 单调栈 全是1的最大子矩阵的变形,不能直接把所有的面积存起来然后排序取第二大的,因为次大子矩阵可能在最大子矩阵里面,比如: 1 0 0 1 ...
- 2019 牛客暑期多校 第八场 A All-one Matrices (单调栈+前缀和)
题目:https://ac.nowcoder.com/acm/contest/888/A 题意:找全1矩阵的个数,并且这个全1矩阵不被其他全1矩阵包含 思路:这里引用付队说的话 -> { 这类问 ...
- [题解] 2019牛客暑期多校第三场H题 Magic Line
题目链接:https://ac.nowcoder.com/acm/contest/883/H 题意:二维平面上有n个不同的点,构造一条直线把平面分成两个点数相同的部分. 题解:对这n个点以x为第一关键 ...
- 【2019牛客暑期多校第三场】J题LRU management
题目链接 题意 好吧,这道题我其实看都没看过,队友跟我说了说这道题是模拟题,卡时间.然后我就上了-- 大致就是维护一个线性表,然后有两种操作:插入.查询 插入时,如果这个值(string)之前出现过, ...
- 2019牛客暑期多校训练营(第九场) D Knapsack Cryptosystem
题目 题意: 给你n(最大36)个数,让你从这n个数里面找出来一些数,使这些数的和等于s(题目输入),用到的数输出1,没有用到的数输出0 例如:3 4 2 3 4 输出:0 0 1 题解: 认真想一 ...
- 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)
layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...
- [暴力+前缀和]2019牛客暑期多校训练营(第六场)Upgrading Technology
链接:https://ac.nowcoder.com/acm/contest/886/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
随机推荐
- hdu 4419 Colourful Rectangle (离散化扫描线线段树)
Problem - 4419 题意不难,红绿蓝三种颜色覆盖在平面上,不同颜色的区域相交会产生新的颜色,求每一种颜色的面积大小. 比较明显,这题要从矩形面积并的方向出发.如果做过矩形面积并的题,用线段树 ...
- 2019-9-2-C#枚举中使用Flags特性
title author date CreateTime categories C#枚举中使用Flags特性 lindexi 2019-09-02 12:57:37 +0800 2018-2-13 1 ...
- npx cowsay 让动物说话~
发现个好玩的东东, 忍不住想分享出来, 好可爱, 哈哈哈~~ node环境执行命令: npm i cowsay -D npx cowsay hello! npx cowsay -f sh ...
- js创建对象的三种方式和js工厂模式创建对象
文章地址: https://www.cnblogs.com/sandraryan/ 创建对象 创建对象的三种方式 构造函数 ,是一种特殊的方法.主要用来在创建对象时初始化对象 1. 调用系统的构造函数 ...
- HDU 1596 也是最小路径Dijkstra
#include<cstdio> #include<cmath> #include<cstring> +; double dist[qq]; double city ...
- 5 分钟入门 Google 最强NLP模型:BERT
BERT (Bidirectional Encoder Representations from Transformers) 10月11日,Google AI Language 发布了论文 BERT: ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树
题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...
- [转]C#操作Memcached帮助类
在VS中安装Memcached,直接在NuGet下搜索Memcached,选择第一个进行安装: 服务端资源下载地址:https://pan.baidu.com/s/1gf3tupl 接下来开始写程序, ...
- @ENABLEWEBSECURITY和@ENABLEWEBMVCSECURITY有什么区别?
@EnableWebSecurity和@EnableWebMvcSecurity有什么区别? @EnableWebSecurity JavaDoc文档: 将此注释添加到@Configuration类中 ...
- PHP mysqli扩展整理,包括面向过程和面向对象的比较\事务控制\批量执行\预处理
相关文章:PHP的mysql扩展整理,操作数据库的实现过程分析 PHP PDO扩展整理,包括环境配置\基本增删改查\事务\预处理 介绍 mysqli是PHP程序与mysql数据库进行数据交互的桥梁, ...