栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Codeforces Round #805 (Div. 3)(A~B)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Codeforces Round #805 (Div. 3)(A~B)

https://codeforces.com/contest/1702https://codeforces.com/contest/1702

A. Round Down the Price

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

Copy

7
1
2
178
20
999999999
9000
987654321

output

Copy

0
1
78
10
899999999
8000
887654321

Note

In the example:

  • 1−0=1001−0=100,
  • 2−1=1002−1=100,
  • 178−78=102178−78=102,
  • 20−10=10120−10=101,
  • 999999999−899999999=108999999999−899999999=108,
  • 9000−8000=1039000−8000=103,
  • 987654321−887654321=108987654321−887654321=108.

Note that in each test case, we get the maximum possible round number.

这道题目要求降价,具体降价要求就是需要取一个最接近价格并且不大于价格的10的次方数。要注意最后输出用printf,count会科学计数。

#include  
#include 
#include 
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int prize,x=1,flag=0;
		cin>>prize;
		while(prize>=x)
		{
			x=x*10;
			flag++;
		}
		prize-=pow(10,flag-1);
		printf("%dn",prize);
	}
}
B. Polycarp Writes a String from Memory

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:

  • on the first day Polycarp will memorize the letters l, o, i and write lolli;
  • On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops.

If Polycarp wants to write the string stringology, he will do it in 44 days:

  • in the first day will be written part str;
  • on day two will be written part ing;
  • on the third day, part of olog will be written;
  • on the fourth day, part of y will be written.

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

6
lollipops
stringology
abracadabra
codeforces
test
f

output

Copy

2
4
3
4
1
1

这题需要用到容器中的map,key值存字符,value存字符出现次数,因为一次最多只能出现三个不同的字符,所以如果容器中等于三个字符时,判断新进来的字符容器中是否已经存在,存在的话,加入即可。不存在的话,清空容器,重新开始第二轮,并且计数器+1 。要注意的是,最后可能会有剩余的字符并且不足三个,不会被清空计数器也不会+1,所以在最后我们还需要对容器进行检查是否有剩余,有的话+1。

#include 
#include 
#include 
#include 
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int flag=0;
		string s;
		cin>>s;
		maphash;
		for(int i=0;i0)flag++;
		cout< 
C. Train and Queries 

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:

  • a1=3a1=3, b1=5b1=5

    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.

  • a2=1a2=1, b2=7b2=7

    You cannot travel from station 11 to station 77 because the train cannot travel in the opposite direction. Answer: NO.

  • a3=3a3=3, b3=10b3=10

    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:

  • YES, if you can travel by train from the station with index ajaj to the station with index bjbj
  • NO otherwise.

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

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

output

Copy

YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
YES

Note

The first test case is explained in the problem statement.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1014271.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号