问题 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;}
}