2024牛客五一集训派对day1

2024-05-02 16:20

本文主要是介绍2024牛客五一集训派对day1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

B. Coffee Chicken

链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

题目描述

Dr. JYY has just created the Coffee Chicken strings, denoted as S(n). They are quite similar to the Fibonacci soup --- today's soup is made by mingling yesterday's soup and the day before yesterday's soup:
- S(1)="COFFEE"S(1) = \texttt{"COFFEE"}S(1)="COFFEE";
- S(2)="CHICKEN"S(2) = \texttt{"CHICKEN"}S(2)="CHICKEN";
- S(n) = S(n-2) :: S(n-1), where :: denotes string concatenation.
The length of S(n) quickly gets out of control as n increases, and there would be no enough memory in JYY's game console to store the entire string. He wants you to find 10 contiguous characters in S(n), starting from the kth character.

输入描述:

The first line of input is a single integer T (1≤T≤1000)(1 \leq T \leq 1000)(1≤T≤1000), denoting the number of test cases. Each of the following T lines is a test case, which contains two integers n, k (1≤n≤500,1≤k≤min⁡{∣S(n)∣,1012})(1 \leq n \leq 500, 1 \leq k \leq \min\{|S(n)|, 10^{12}\})(1≤n≤500,1≤k≤min{∣S(n)∣,1012}). |S| denotes the length of string S.

输出描述:

For each test case, print the answer in one line. If there are no enough characters from the kth character, output all characters until the end of the string.

示例1

输入

复制2 3 4 2 7

2
3 4
2 7

输出

复制FEECHICKEN N

FEECHICKEN
N

思路:这题其实就是一个斐波那契数列的延申,和队友研究了一阵子怎么减少时间复杂度,怎么减枝优化字串长度,其实直接根本不需要去计算字串长度,更不用去记录字串是什么,内存会炸,所以就是采用递归或者迭代的思想,这里队长和我想到一起去了,下面是队长和我的代码(队长的是前者) 

主要的思路就是将每个字串分成两部分,也就是f(n- 1)和f(n - 2)这两部分,然后看k在哪个区间内,一直往前找,其中的f(n - 1)等也是按照同样的方法向前找,直到找到第一或者第二个字串就结束(因为所有的字符都是从这里传出去的,当然能从这两个字串里面找出来)

然后10个字符或者比这少的字符直接按照和k一样进行计算就行了,需要注意的是,最好把int换成long long 队长和我都是卡了这个,其实改了就可以全过了。其实我这里用的是dp,主要是想到这个问题很dp,就是子问题之间有依赖关系,然后可以列状态转移方程,(最优子结构(问题的最优解可以由其子问题的最优解来构造),然后还有子问题重叠)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N=1e12+10;
ll num[505];
char s[2][20]={"COFFEE","CHICKEN"};
void f(){num[1]=6,num[2]=7;for(int i=3;i<=60;i++){num[i]=min(num[i-2]+num[i-1],N);}
}void findd(int n,ll kk){if (n==1) cout<<s[0][kk-1];else if (n==2) cout<<s[1][kk-1];else{if (kk>num[n-2]) findd(n-1,kk-num[n-2]);else findd(n-2,kk);}
}int main() {f();ll time,n,k;cin>>time;while(time--){cin>>n>>k;if (n>=58){if (n%2==0) n=56;else n=57;}for(ll i=k;i<min(num[n]+1,k+10);i++){findd(n,i);}cout<<endl;}return 0;
}

 

#include "bits/stdc++.h"
using namespace std;
typedef pair<double, double> PII;
typedef long long ll;
PII dp[600];
int main(){int n;cin>>n;long long  a;double  b;string s[4];s[1] = "COFFEE";s[2] = "CHICKEN";dp[1].first = 0;dp[2].first = 0;dp[1].second = 6;dp[2].second = 7;for(int i = 3; i <= 500; i ++){dp[i].first = dp[i - 2].second ;dp[i].second = dp[i - 2].second + dp[i - 1].second;}while(n --){cin>>a>>b;ll aa = a, bb = b;int end = -1;if(10  > dp[a].second - b + 1) end = dp[a].second - b+ 1;if(end != -1) end = min(end, 10);else end = 10;string s1 = "";for(ll i = b; i < b + end; i ++){a = aa;ll t = i;while(a >= 3){if(t > dp[a].first)  t = t - dp[a].first, a = a - 1 ;else a = a - 2;}s1 += s[a][t - 1];}    cout<<s1;if(n != 0) cout<<endl;}return 0;
}

 F. Popping Balloons

链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

Recently, an interesting balloon-popping game can be commonly found near the streets. The rule of this game is quite simple: some balloons are tied to cells of a lattice, and you are allowed to throw some darts to prick the balloons. The more balloons you pierce, the more incredible prize you will get.

Probably because too many people have got bored with this childish game, a new variation of the game has appeared. In this variation, you should prick the balloons by shooting an air rifle instead of throwing darts. You can make six shots in total, three horizontally and three vertically. If you shoot horizontally (vertically, resp.), all balloons in the row (column, resp.) are popped. In order to increase the difficulty, there is one restriction imposed on your shots: the distances between any two adjacent horizontal shots and any two adjacent vertical shots must all equal to a given number rrr. The problem is, what is the maximum number of balloons you can pop by making three horizontal and three vertical shots, under the aforementioned restriction.

输入描述:

The first line of input is two integers n, r (1≤n,r≤105)(1 \leq n, r \leq 10^5)(1≤n,r≤105), the number of balloons and the distance between any two adjacent horizontal or vertical shots.The remaining part of the input is n lines, specifying the positions of the balloons. Each of these lines contains two integers x, y (0≤x,y≤105)(0 \leq x, y \leq 10^5)(0≤x,y≤105), denoting a balloon positioned at (x, y). Note that multiple balloons may lie in the same position.

输出描述:

Output the answer as a single integer in one line.

示例1

输入

复制7 1 0 0 1 1 2 2 3 3 4 4 5 5 7 8

7 1
0 0
1 1
2 2
3 3
4 4
5 5
7 8

输出

复制6

6

示例2

输入

复制5 2 0 10 2 3 5 7 9 6 2 3

5 2
0 10
2 3
5 7
9 6
2 3

输出

复制4

4

思路:

这道题借鉴了大佬的思路,比较清晰,主要就是暴力枚举每种可能,因为题目给的时间很长,所以直接尝试,然后首先找边界,缩小时间,然后统计每一行每一列的分数,然后求出每隔r行(列) 的所有的分数的可能,进行排列,找最大的前六组(行列都是),各选三组进行求和,然后进行比较(记得减去中间重叠部分),就是我们需要的答案。

#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 100;
struct HL{int id, num;
}a[N], b[N];
bool cmp(HL x, HL y){return x.num > y.num;
}
map<int, map<int, int> > mp;
int row[N], col[N];
int main(){
// 	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);int n, r, x, y, ans = 0;scanf("%d%d",&n,&r);int maxx = 0, maxy = 0;int minx= 1e6, miny = 1e6;for(int i = 0; i < n; i ++){scanf("%d%d",&x,&y);minx = min(minx, x);miny = min(miny, y);maxx = max(maxx, x);maxy = max(maxy, y); mp[x][y]++;col[x] ++;row[y] ++;
//		a[i].id = i;
//		a[i].num += }for(int i =minx; i <= maxx; i ++){a[i].id = i;a[i].num = col[i];if(i + r <= maxx) a[i].num += col[i + r];if(i - r >= minx) a[i].num += col[i - r];}sort(a + minx, a + maxx, cmp);for(int i = miny; i <= maxy; i ++){b[i].id = i;b[i].num = row[i];if(i + r <= maxy) b[i].num += row[i + r];if(i - r >= miny) b[i].num += row[i - r];}sort(b + miny, b + maxy, cmp);for(int i = minx; i <= minx + 5; i ++){for(int j = miny; j <= miny + 5; j ++){int temp = a[i].num + b[j].num;int xx = a[i].id, yy = b[j].id;temp -= mp[xx][yy] + mp[xx][yy - r] + mp[xx][yy + r];temp -= mp[xx + r][yy] + mp[xx + r][yy + r] + mp[xx + r][yy - r];temp -= mp[xx - r][yy] + mp[xx - r][yy + r] + mp[xx - r][yy - r];ans = max(ans, temp);}}printf("%d\n",ans);return 0;
}

 

 链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

Recently, an interesting balloon-popping game can be commonly found near the streets. The rule of this game is quite simple: some balloons are tied to cells of a lattice, and you are allowed to throw some darts to prick the balloons. The more balloons you pierce, the more incredible prize you will get.

Probably because too many people have got bored with this childish game, a new variation of the game has appeared. In this variation, you should prick the balloons by shooting an air rifle instead of throwing darts. You can make six shots in total, three horizontally and three vertically. If you shoot horizontally (vertically, resp.), all balloons in the row (column, resp.) are popped. In order to increase the difficulty, there is one restriction imposed on your shots: the distances between any two adjacent horizontal shots and any two adjacent vertical shots must all equal to a given number rrr. The problem is, what is the maximum number of balloons you can pop by making three horizontal and three vertical shots, under the aforementioned restriction.

输入描述:

The first line of input is two integers n, r (1≤n,r≤105)(1 \leq n, r \leq 10^5)(1≤n,r≤105), the number of balloons and the distance between any two adjacent horizontal or vertical shots.The remaining part of the input is n lines, specifying the positions of the balloons. Each of these lines contains two integers x, y (0≤x,y≤105)(0 \leq x, y \leq 10^5)(0≤x,y≤105), denoting a balloon positioned at (x, y). Note that multiple balloons may lie in the same position.

输出描述:

Output the answer as a single integer in one line.

示例1

输入

复制7 1 0 0 1 1 2 2 3 3 4 4 5 5 7 8

7 1
0 0
1 1
2 2
3 3
4 4
5 5
7 8

输出

复制6

6

示例2

输入

复制5 2 0 10 2 3 5 7 9 6 2 3

5 2
0 10
2 3
5 7
9 6
2 3

输出

复制4

4

 

 思路,这道题目其实就是一道水题,直接用vector数组进行存边,然后发现每一个形状都或多或少的边的情况不一样,由于形状很少,所以可以直接进行判断。这里我使用了一个s数组,用来存每一个图形的边的数量,s的下标表示某点连接的边数(出度或者入度),值就表示有几个点,比如s[i] = x; 就是有i条边的点有x个。

#include "bits/stdc++.h"
#include "string.h"
using namespace std;
vector<int> v[7];
int s[20];
int main(){int n;cin>>n;while(n--){for(int i = 1; i <= 6; i ++) v[i].clear();memset(s, 0, sizeof(s));int flag = -1;int a, b;int ans1 = 0, ans2 = 0;for(int i = 0; i < 5; i ++){cin>>a>>b;v[a].push_back(b);v[b].push_back(a);}for(int i = 1; i <= 6; i ++){s[v[i].size()] ++;if(v[i].size() == 3){flag = i;}}for(int i = 1; i <= 4; i ++){if(i == 3 && s[i] == 1){if(flag != -1){for(int j = 0; j <v[flag].size(); j ++){if(v[v[flag][j]].size() == 1) ans1 ++;else ans2 ++;}}break;	}}if(ans1 == 2) cout<<"2-methylpentane"<<endl;else if(ans1 == 1 && ans2 == 2) cout<<"3-methylpentane"<<endl;else if(s[1] == 4 && s[3] == 2) cout<<"2,3-dimethylbutane"<<endl;else if(s[4] == 1 ) cout<<"2,2-dimethylbutane"<<endl;else if(s[1] == 2 && s[2] == 4) cout<<"n-hexane"<<endl;}return 0;
} 

 

这篇关于2024牛客五一集训派对day1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/954669

相关文章

创新、引领、发展——SAMPE中国2024年会在京盛大开幕

绿树阴浓夏日长,在这个色彩缤纷的季节,SAMPE中国2024年会暨第十九届国际先进复合材料制品原材料、工装及工程应用展览会在中国国际展览中心(北京朝阳馆)隆重开幕。新老朋友共聚一堂,把酒话桑麻。 为期4天的国际学术会议以“先进复合材料,引领产业创新与可持续化发展”为主题,设立了34个主题分会场,其中包括了可持续化会场、国际大学生会场、中法复合材料制造技术峰会三个国际会场和女科技工作者委员会沙龙,

2024年6月24日-6月30日(ue独立游戏为核心)

试过重点放在独立游戏上,有个indienova独立游戏团队是全职的,由于他们干了几个月,节奏暂时跟不上,紧张焦虑了。五一时也有点自暴自弃了,实在没必要,按照自己的节奏走即可。精力和时间也有限,放在周末进行即可。除非哪天失业了,再也找不到工作了,再把重心放在独立游戏上。 另外,找到一个同样业余的美术,从头做肉鸽游戏,两周一次正式交流即可。节奏一定要放慢,不能影响正常工作生活。如果影响到了,还不如自

潜艇伟伟迷杂交版植物大战僵尸2024最新免费安卓+ios苹果+iPad分享

嗨,亲爱的游戏迷们!今天我要给你们种草一个超有趣的游戏——植物大战僵尸杂交版。这款游戏不仅继承了原有经典游戏的核心玩法,还加入了许多创新元素,让玩家能够体验到前所未有的乐趣。快来跟随我一起探索这个神奇的世界吧! 植物大战僵尸杂交版最新绿色版下载链接: https://pan.quark.cn/s/d60ed6e4791c 🔥 创新与经典的完美结合 植物大战僵尸杂交版在保持了原游戏经典玩

Chromium 调试指南2024 - 远程开发(下)

1. 引言 在《Chromium 调试指南2024 - 远程开发(上)》中,我们探讨了远程开发的基本概念、优势以及如何选择合适的远程开发模式。掌握了这些基础知识后,接下来我们将深入了解如何在远程环境中高效地进行Chromium项目的调试工作。 调试是开发过程中至关重要的一环,特别是对于像Chromium这样复杂的大型项目。远程调试不仅可以充分利用远程服务器的强大计算资源,还能确保开发环境的一致

【2024最新版】Java JDK安装配置全攻略:图文详解

目录 1. 引言2. 准备工作2.1 **确定操作系统**2.2 **检查系统要求**2.3 **下载JDK安装包**3. 安装步骤(以Windows系统为例)4. 配置环境变量4.1 jdk配置验证4.2 **配置JAVA_HOME环境变量**4.3 **配置Path环境变量**4.4 验证jdk是否配置成功 5. 结语 1. 引言 随着技术的不断发展和更新,Java作为世界上

【团队成长】2024-25周周报-业务介绍内容创作

大家好!我们是IndustryOR 团队,致力于分享业界落地的算法技术。欢迎关注微信公众号/知乎/CSDN【运筹匠心】 。 记录人:张哲铭,某互联网大厂算法专家 【团队成长/个人成长】系列的推文会以 【工作周报】 的方式记录IndustryOR团队及其成员的成长过程,请大家一起见证和参与我们团队从0-1-N的发展过程。 记录人顺序:张哲铭-向杜兵-高欣甜-黄世鸿-许佳鸣

2024老年护理新前沿:养老实训室的创新应用

随着人口老龄化的加速,如何为老年人提供优质的养老服务已成为社会关注的重点。在这一背景下,养老实训室应运而生,成为培养专业养老人才、改善老年人生活质量的新兴平台。与传统的课堂教学相比,养老实训室能够为学员提供更为生动、贴近实际的培训体验,为老年护理事业注入创新动力。 一、养老实训室的功能优势 模拟真实环境,提升操作技能 养老实训室通过还原老年人的居住环境,如卧室、浴室等,让学员能实际操作各种日

湖北民族大学2024年成人高等继续教育招生简章

湖北民族大学,这所承载着深厚文化底蕴和卓越教育理念的学府,在崭新的2024年再次敞开怀抱,热烈欢迎有志于深化学习、提升自我的成人学员们。今年的成人高等继续教育招生,不仅是学校对于终身教育理念的具体实践,更是为广大社会人士提供了一次难得的学习机会。 湖北民族大学,以其悠久的历史、优秀的师资和卓越的教学质量,早已在成人教育领域树立了良好的口碑。学校秉承“博学、博爱、立人、达人”的校训,致力于培养

▶《强化学习的数学原理》(2024春)_西湖大学赵世钰 Ch5 蒙特卡洛方法【model-based ——> model-free】

PPT 截取必要信息。 课程网站做习题。总体 MOOC 过一遍 1、视频 + 学堂在线 习题 2、 过 电子书 是否遗漏 【下载:本章 PDF GitHub 页面链接 】 【第二轮 才整理的,忘光了。。。又看了一遍视频】 3、 过 MOOC 习题 看 PDF 迷迷糊糊, 恍恍惚惚。 学堂在线 课程页面链接 中国大学MOOC 课程页面链接 B 站 视频链接 PPT和书籍下载网址: 【Gi

2023-2024 学年第二学期小学数学六年级期末质量检测模拟(制作:王胤皓)(90分钟)

word效果预览: 一、我会填 1. 1.\hspace{0.5em} 1. 一个多位数,亿位上是次小的素数,千位上是最小的质数的立方,十万位是 10 10 10 和 15 15 15 的最大公约数,万位是最小的合数,十位上的数既不是质数也不是合数,这个数是 ( \hspace{4em} ),约等于 ( \hspace{1em} ) 万 2. 2.\hspace{0.5em} 2.