21.01.22 NO.27

news/2025/1/15 17:48:10/

问题 B: 图书管理员
题目描述
图书馆中每本书都有一个图书编码,可以用于快速检索图书,这个图书编码是一个正整数。
每位借书的读者手中有一个需求码,这个需求码也是一个正整数。如果一本书的图书编码恰好以读者的需求码结尾,那么这本书就是这位读者所需要的。
小 D 刚刚当上图书馆的管理员,她知道图书馆里所有书的图书编码,她请你帮她写一个程序,对于每一位读者,求出他所需要的书中图书编码最小的那本书,如果没有他需要的书,请输出-1。
输入
第一行,包含两个正整数 n 和 q,以一个空格分开,分别代表图书馆里书的数量和读者的数量。
接下来的 n 行,每行包含一个正整数,代表图书馆里某本书的图书编码。
接下来的 q 行,每行包含两个正整数,以一个空格分开,第一个正整数代表图书馆里读者的需求码的长度,第二个正整数代表读者的需求码。
输出
输出有 q 行,每行包含一个整数,如果存在第 i 个读者所需要的书,则在第 i行输出第 i 个读者所需要的书中图书编码最小的那本书的图书编码,否则输出-1。
样例输入 Copy
5 5
2123
1123
23
24
24
2 23
3 123
3 124
2 12
2 12
样例输出 Copy
23
1123
-1
-1
-1
提示
第一位读者需要的书有 2123、1123、23,其中 23 是最小的图书编码。第二位读者需要的书有 2123、1123,其中 1123 是最小的图书编码。对于第三位,第四位和第五位读者,没有书的图书编码以他们的需求码结尾,即没有他们需要的书,输出-1。
对于 20%的数据,1 ≤ n ≤ 2。
另有 20%的数据,q = 1。
另有 20%的数据,所有读者的需求码的长度均为 1。
另有 20%的数据,所有的图书编码按从小到大的顺序给出。
对于 100%的数据,1 ≤ n ≤ 1,000,1 ≤ q ≤ 1,000,所有的图书编码和需求码均不超过 10,000,000。

可以用个pow函数,求余数

#include <bits/stdc++.h>
using namespace std;
int book[1010],i,j;
int main()
{int booknum,readernum;cin>>booknum>>readernum;for(i=0;i<booknum;i++){cin>>book[i];}sort(book,book+booknum);int flag,id,len;for(i=0;i<readernum;i++){flag=0;cin>>len>>id;int k=pow(10,len);for(j=0;j<booknum;j++){if(book[j]%k==id){flag=1;cout<<book[j]<<endl;break;}}if(flag==0){cout<<"-1"<<endl;}}
}

问题 F: Choose Integers
题目描述
We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.
If the objective is achievable, print YES. Otherwise, print NO.

Constraints
1≤A≤100
1≤B≤100
0≤C<B
输入
Input is given from Standard Input in the following format:
A B C
输出
Print YES or NO.
样例输入 Copy
7 5 1
样例输出 Copy
YES
提示
For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.
理解题意就好

#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{cin>>a>>b>>c;{int flag = 0;for(int k = 1; k<=10000000; k++){if((b*k+c) % a == 0){cout<<"YES";flag = 1;break;}}if(flag==0){cout<<"NO";}}
}

问题 G: Sentou
题目描述
In a public bath, there is a shower which emits water for T seconds when the switch is pushed.
If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower. The i-th person will push the switch ti seconds after the first person pushes it.
How long will the shower emit water in total?

Constraints
1≤N≤200,000
1≤T≤109
0=t1<t2<t3<,…,<tN−1<tN≤109
T and each ti are integers.
输入
Input is given from Standard Input in the following format:
N T
t1 t2 … tN
输出
Assume that the shower will emit water for a total of X seconds. Print X.
样例输入 Copy
2 4
0 3
样例输出 Copy
7
提示
Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

这个就是求时间间隔和t的较大值然后累加就行
不要忘了最后一次开后还要出水t的时间

#include <bits/stdc++.h>
using namespace std;
int n,t,i;
int a[200010];
int ans;
int main()
{cin>>n>>t;for (i=1;i<=n;i++){cin>>a[i];}for (i=1;i<n;i++){ans+=min(a[i+1]-a[i],t);}cout<<ans+t;
}

问题 L: Block Game
题目描述
Farmer John is trying to teach his cows to read by giving them a set of N spelling boards typically used with preschoolers (1≤N≤100). Each board has a word and an image on each side. For example, one side might have the word ‘cat’ along with a picture of a cat, and the other side might have the word ‘dog’ along with a picture of a dog. When the boards are lying on the ground, N words are therefore shown. By flipping over some of the boards, a different set of N words can be exposed.
To help the cows with their spelling, Farmer John wants to fashion a number of wooden blocks, each embossed with a single letter of the alphabet. He wants to make sufficiently many blocks of each letter so that no matter which set of Nwords is exposed on the upward-facing boards, the cows will be able to spell all of these words using the blocks. For example, if N=3 and the words ‘box’, ‘cat’, and ‘car’ were facing upward, the cows would need at least one ‘b’ block, one ‘o’ block, one ‘x’ block, two ‘c’ blocks, two ‘a’ blocks, one ‘t’ block, and one ‘r’ block.

Please help the Farmer John determine the minimum number of blocks for each letter of the alphabet that he needs to provide, so that irrespective of which face of each board is showing, the cows can spell all N visible words.

输入
Line 1 contains the integer N.
The next N lines each contain 2 words separated by a space, giving the two words on opposite sides of a board. Each word is a string of at most 10 lowercase letters.
输出
Please output 26 lines. The first output line should contain a number specifying the number of copies of ‘a’ blocks needed. The next line should specify the number of ‘b’ blocks needed, and so on.
样例输入 Copy
3
fox box
dog cat
car bus
样例输出 Copy
2
2
2
1
0
1
1
0
0
0
0
0
0
0
2
0
0
1
1
1
1
0
0
1
0
0
提示
In this example, there are N=3 boards, giving 23=8 possibilities for the set of upward-facing words:

fox dog car
fox dog bus
fox cat car
fox cat bus
box dog car
box dog bus
box cat car
box cat bus
We need enough blocks for each letter of the alphabet so that we can spell all three words, irrespective of which of these eight scenarios occurs.

题目大意就是给几组板的两面的单词,然后计算每个字母所需要的最少的数量

#include <bits/stdc++.h>
using namespace std;
char str1[105],str2[105];
int a[27],b[27];
int A[27];
int i,j,len1,len2;
int main()
{int n;cin>>n;for(i=1; i<=n; i++){cin>>str1>>str2;len1=strlen(str1);len2=strlen(str2);for(j=0;j<max(len1,len2); j++){if(j<len1){a[str1[j]-'a']++;}if(j<len2){b[str2[j]-'a']++;}}for(j=0;j<26;j++){A[j]+=max(a[j],b[j]);a[j]=0;b[j]=0;}//不要忘记初始化}for(i=0; i<26; i++){cout<<A[i]<<endl;}
}

问题 M: The Cow-Signal
题目描述
Bessie and her cow friends are playing as their favorite cow superheroes. Of course, everyone knows that any self-respecting superhero needs a signal to call them to action. Bessie has drawn a special signal on a sheet of M×N paper (1≤M≤10,1≤N≤10), but this is too small, much too small! Bessie wants to amplify the signal so it is exactly K times bigger (1≤K≤10) in each direction.
The signal will consist only of the ‘.’ and ‘X’ characters.
输入
The first line of input contains M, N, and K, separated by spaces.
The next M lines each contain a length-N string, collectively describing the picture of the signal.
输出
You should output KM lines, each with KN characters, giving a picture of the enlarged signal.
样例输入 Copy
5 4 2
XXX.
X…X
XXX.
X…X
XXX.
样例输出 Copy
XXXXXX…
XXXXXX…
XX…XX
XX…XX
XXXXXX…
XXXXXX…
XX…XX
XX…XX
XXXXXX…
XXXXXX…

一道简单的模拟题,可以先把每一行变为k倍,然后按行输出

#include <bits/stdc++.h>
using namespace std;
int main()
{int n,m,k;char a[15][15],b[105][105];int i,j;cin>>n>>m>>k;for(i=0;i<n;i++){for(j=0;j<m;j++){cin>>a[i][j];}}int x=m*k;for(i=0;i<n;i++){for(j=0;j<x;j++){int y=j/k;b[i][j]=a[i][y];}}for(i=0;i<n*k;i++){int z=i/k;for(j=0;j<x;j++){cout<<b[z][j];}cout<<endl;}
}

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

相关文章

nini

nini 是一个用来解析 INI配置文件的C#库&#xff0c;支持中文编码。 主页&#xff1a;http://nini.sourceforge.net

欢迎来到 VOXEL WARS!

Sandbox Streams 的全新节目&#xff0c;我们希望你们能参与其中&#xff01; 我们正在寻找 15 名 Voxedit 艺术家&#xff0c;他们将需要抽出 1 小时进行现场表演&#xff08;仅限屏幕共享&#xff09;&#xff0c;并在节奏快速的环境中进行创作&#xff0c;以赢得“最佳快速设…

结合符号性记忆,清华等提出ChatDB,提升大模型的复杂推理能力

结合符号性记忆&#xff0c;清华等提出ChatDB&#xff0c;提升大模型的复杂推理能力 随着大语言模型&#xff08;Large Language Models&#xff09;的爆火&#xff0c;例如 ChatGPT&#xff0c;GPT-4&#xff0c;PaLM&#xff0c;LLaMA 等&#xff0c;如何让大语言模型更好的…

100种思维模型之马斯洛需求层次理论-81

马斯洛需求层次理论是人本主义科学理论之一&#xff0c;由美国心理学家亚伯拉罕马斯洛在1943年在《人类激励理论》论文中所提出。 文中将人类需求像阶梯一样从低到高按层次分为五种&#xff0c;分别是&#xff1a;生理需求、安全需求、社交需求、尊重需求和自我实现需求。 一、…

python儿童教程-02

Python基础语法 接下来我们来学习Python的基础语法&#xff0c;包括变量、数据类型、运算符、条件语句、循环语句等。 &#xff08;1&#xff09;变量 在Python中&#xff0c;变量是用来存储数据的。Python的变量不需要声明&#xff0c;直接赋值即可。例如&#xff1a; x …

对TS里接口、extends和类的理解

对TS里接口和类的理解 接口 需求: 创建人的对象, 需要对人的属性进行一定的约束 下面通过一个简单示例来观察接口是如何工作的&#xff1a; /* 在 TypeScript 中&#xff0c;我们使用接口&#xff08;Interfaces&#xff09;来定义对象的类型 接口: 是对象的状态(属性)和行…

Express框架与Mongodb的结合使用

前言 如果你打开这篇文章&#xff0c;说明已经开始有做项目的打算了。 这里有express和mongodb的相关参考教程&#xff0c;遇到问题可以在里面找到答案&#xff1a; Express框架从入门到如土 一文入门Mongodb 这里说下为什么要express框架和mongodb结合。express框架不是指单…

wsl中docker自启动

前言 wsl -l -v # 查看 wsl 的状态 wsl -t Ubuntu # 关闭指定版本 wsl -d Ubuntu # 启动指定版本 启动 docker 通过命令 ps -p 1 -o comm 我们知道我们用的是 init&#xff0c;故我们将 systemd 命令修改为 SysV init命令。 ps -p 1 -o comm 更换命令&#xff0c;用SysV in…