目录
A. Round Down the Price
B. Polycarp Writes a String from Memory
C. Train and Queries
D. Not a Cheap String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
At the store, the salespeople want to make all prices round.
In this problem, a number that is a power of 1010 is called a round number. For example, the numbers 100=1100=1, 101=10101=10, 102=100102=100 are round numbers, but 2020, 110110 and 256256 are not round numbers.
So, if an item is worth mm bourles (the value of the item is not greater than 109109), the sellers want to change its value to the nearest round number that is not greater than mm. They ask you: by how many bourles should you decrease the value of the item to make it worth exactly 10k10k bourles, where the value of kk — is the maximum possible (kk — any non-negative integer).
For example, let the item have a value of 178178-bourles. Then the new price of the item will be 100100, and the answer will be 178−100=78178−100=78.
Input
The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases .
Each test case is a string containing a single integer mm (1≤m≤1091≤m≤109) — the price of the item.
Output
For each test case, output on a separate line a single integer dd (0≤d Example input output 题意:输入一个数m,输出一个数ans,m-ans是10的几次幂 思路:判断m是几位数,再让m减去10的位数次幂 代码: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Polycarp has a poor memory. Each day he can remember no more than 33 of different letters. Polycarp wants to write a non-empty string of ss consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it? Polycarp initially has an empty string and can only add characters to the end of that string. For example, if Polycarp wants to write the string lollipops, he will do it in 22 days: If Polycarp wants to write the string stringology, he will do it in 44 days: For a given string ss, print the minimum number of days it will take Polycarp to write it. Input The first line of input data contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Each test case consists of a non-empty string ss consisting of lowercase Latin letters (the length of the string ss does not exceed 2⋅1052⋅105) — the string Polycarp wants to construct. It is guaranteed that the sum of string lengths ss over all test cases does not exceed 2⋅1052⋅105. Output For each test case, print a single number — minimum number of days it will take Polycarp to write the string ss from memory. Example input Copy output Copy 思路:输入一个字符串s,每次只能记忆三个单词,定义set容器,因为set容器里的元素具有唯一性。遍历s,把s的字符insert到set容器里,如果set.size()>3,计数。再把set容器清空,重新insert,在上次停止的位置。 代码: time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Along the railroad there are stations indexed from 11 to 109109. An express train always travels along a route consisting of nn stations with indices u1,u2,…,unu1,u2,…,un, where (1≤ui≤1091≤ui≤109). The train travels along the route from left to right. It starts at station u1u1, then stops at station u2u2, then at u3u3, and so on. Station unun — the terminus. It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values u1,u2,…,unu1,u2,…,un. You are given kk queries, each containing two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109). For each query, determine whether it is possible to travel by train from the station with index ajaj to the station with index bjbj. For example, let the train route consist of 66 of stations with indices [3,7,1,5,1,43,7,1,5,1,4] and give 33 of the following queries: It is possible to travel from station 33 to station 55 by taking a section of the route consisting of stations [3,7,1,53,7,1,5]. Answer: YES. You cannot travel from station 11 to station 77 because the train cannot travel in the opposite direction. Answer: NO. It is not possible to travel from station 33 to station 1010 because station 1010 is not part of the train's route. Answer: NO. Input The first line of the input contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case is empty. The second line of each test case contains two integers: nn and kk (1≤n≤2⋅105,1≤k≤2⋅1051≤n≤2⋅105,1≤k≤2⋅105) —the number of stations the train route consists of and the number of queries. The third line of each test case contains exactly nn integers u1,u2,…,unu1,u2,…,un (1≤ui≤1091≤ui≤109). The values u1,u2,…,unu1,u2,…,un are not necessarily different. The following kk lines contain two different integers ajaj and bjbj (1≤aj,bj≤1091≤aj,bj≤109) describing the query with index jj. It is guaranteed that the sum of nn values over all test cases in the test does not exceed 2⋅1052⋅105. Similarly, it is guaranteed that the sum of kk values over all test cases in the test also does not exceed 2⋅1052⋅105 Output For each test case, output on a separate line: You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response). Example input Copy output Copy 思路:给定长度为n的数组输入数据为车站号,在给定k组数据,每组两个数据a和b,判断能不能从车站a到达车站b,b的下标大于a的下标,才能从a到b。定义三个map数组,l保留相同车站的情况下,下标最小的,r保留相同车站下,下标最大的,mp.count()计算数据出现的次数和有无出现过。 代码: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let ss be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is 1+2+3+1=71+2+3+1=7. The string ww and the integer pp are given. Remove the minimal number of letters from ww so that its price becomes less than or equal to pp and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string ww is less than or equal to pp, then nothing needs to be deleted and ww must be output. Note that when you delete a letter from ww, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst. Input The first line of input contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the test. The following are descriptions of tt test cases. Each case consists of two lines. The first of them is the string ww, it is non-empty and consists of lowercase Latin letters. Its length does not exceed 2⋅1052⋅105. The second line contains an integer pp (1≤p≤52000001≤p≤5200000). It is guaranteed that the sum of string lengths ww over all test cases does not exceed 2⋅1052⋅105. Output Output exactly tt rows, the ii-th of them should contain the answer to the ii-th set of input data. Print the longest string that is obtained from ww by deleting letters such that its price is less or equal to pp. If there are several answers, then output any of them. Note that the empty string — is one of the possible answers. In this case, just output an empty string. Example input output 思路:先把字符串w对应位的字符转化为数字求和,定义一个数组标记字符串对应的位置,然后把1到26数字转为对应字符,判断没有标记过的,26到1倒着循环,,因为减去较大的,能保证减的最少,如果现在的w[i]等于此时检索字符,sum就可以减去此时的字符,直到sum<=p,停止。 代码:7
1
2
178
20
999999999
9000
987654321
0
1
78
10
899999999
8000
887654321
#include
B. Polycarp Writes a String from Memory
6
lollipops
stringology
abracadabra
codeforces
test
f
2
4
3
4
1
1
#include
C. Train and Queries
3
6 3
3 7 1 5 1 4
3 5
1 7
3 10
3 3
1 2 1
2 1
1 2
4 5
7 5
2 1 1 1 2 4 4
1 3
1 4
2 1
4 1
1 2
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES
#include
D. Not a Cheap String
5
abca
2
abca
6
codeforces
1
codeforces
10
codeforces
100
aa
abc
cdc
codeforces
#include