按难度来吧呜呜呜
CodeForces_ProblemSet
- One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w w w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.俩人找了个 w k g w\ \rm kg w kg的西瓜
- Pete and Billy are great fans of even numbers, that’s why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that’s why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.现在想要分成两个部分,每部分的重量都是他们喜欢的偶数。
Input
The first (and the only) input line contains integer number w w w ( 1 ≤ w ≤ 100 1 \le w \le 100 1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.【输入】输入一个介于 1 ≤ w ≤ 100 1\le w\le 100 1≤w≤100的值,表示西瓜的重量。
Output
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.【输出】如果能满足题意,输出"YES",否则输出"NO"
Examples
[input]
8
[output]
YES
给出python代码…不难写
n = int(input())
print("YES" if n & 1 == 0 and n != 2 else "NO")
这个题目还挺有意思的哈哈哈,双关语
- Sometimes some words like “localization” or “internationalization” are so long that writing them many times in one text is quite tiresome.
- Let’s consider a word too long, if its length is strictly more than 10 10 10 characters. All too long words should be replaced with a special abbreviation.超过 10 10 10个字母的单词太长了,写起来就会很烦,最好有个缩写代替之。
- This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn’t contain any leading zeroes.怎么形成「缩写」呢?我们保留其首尾字母,以及单词长度(不含首尾),用不含前导零的十进制数表示。
- Thus, “localization” will be spelt as “l10n”, and "internationalization» will be spelt as “i18n”.(给出了两个样例)
- You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.请你完成此过程,将长单词改为不可更改的最简单形式。(实际上undergo是「不可忍受的」意思,翻译成「不可」应该比较贴切)
Input
The first line contains an integer n ( 1 ≤ n ≤ 100 ) n (1 ≤ n ≤ 100) n(1 ≤ n ≤ 100). Each of the following n n n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 1 1 to 100 100 100 characters.【输入】第一行包含一个整型 n n n,随后 n n n行,每行包含一个只含有小写字母的字符串,长度为 [ 1 , 100 ] [1,100] [1,100]
Output
Print n n n lines. The i i i-th line should contain the result of replacing of the i-th word from the input data.【输出】包含着 n n n行输出,每行表示更改后的结果。
Examples
[input]
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
[output]
word
l10n
i18n
p43s
#include
#include
using namespace std;
string str;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n; cin >> n;
while (n --) {
cin >> str;
int len = str.length();
if (len <= 10) {
cout << str;
} else {
cout << str[0] << len - 2 << str[len - 1];
}
if (n != 1) cout << '\n';
}
return 0;
}
- One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won’t write the problem’s solution.三人组队参赛,如果有至少两个人认为可以做,那么就开题。
- This contest offers n n n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.每支队伍有 n n n道题,来算算他们要开多少道题叭。
Input
The first input line contains a single integer n ( 1 ≤ n ≤ 1000 ) n (1 ≤ n ≤ 1000) n(1 ≤ n ≤ 1000) — the number of problems in the contest. Then n n n lines contain three integers each, each integer is either 0 0 0 or 1 1 1. If the first number in the line equals 1 1 1, then Petya is sure about the problem’s solution, otherwise he isn’t sure. The second number shows Vasya’s view on the solution, the third number shows Tonya’s view. The numbers on the lines are separated by spaces.【输入】第一行包含一个整型 n n n,随后 n n n行都有三个真值,表示三个人的意愿,以空格分隔。
Output
Print a single integer — the number of problems the friends will implement on the contest.【输出】输出他们要开的题数目
Examples
[input]
3
1 1 0
1 1 1
1 0 0
[output]
2
[input]
2
1 0 0
0 1 1
[output]
1
Note(本题中没啥用)
- In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn’t enough, so the friends won’t take it.
- In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
#include
using namespace std;
int cnt, a, b, c;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int n; cin >> n;
while (n --) {
cin >> a >> b >> c;
cnt += ( a + b + c >= 2 );
}
cout << cnt;
return 0;
}
- “Contestant who earns a score equal to or greater than the k k k-th place finisher’s score will advance to the next round, as long as the contestant earns a positive score…” — an excerpt from contest rules.得分的选手的排名若能超过第 k k k位,就能晋级——摘自比赛规则
- A total of n n n participants took part in the contest ( n ≥ k ) (n ≥ k) (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.已知 n n n位选手以及其得分,计算多少选手能晋级。
Input
The first line of the input contains two integers n n n and k ( 1 ≤ k ≤ n ≤ 50 ) k (1 ≤ k ≤ n ≤ 50) k(1 ≤ k ≤ n ≤ 50) separated by a single space.
The second line contains n n n space-separated integers a 1 , a 2 , … , a n ( 0 ≤ a i ≤ 100 ) a_1, a_2, \dots, a_n (0 ≤ a_i ≤ 100) a1, a2, …, an(0 ≤ ai ≤ 100), where a i a_i ai is the score earned by the participant who got the i i i-th place. The given sequence is non-increasing (that is, for all i i i from 1 1 1 to n − 1 n - 1 n − 1 the following condition is fulfilled: a i ≥ a i + 1 ai ≥ ai + 1 ai ≥ ai + 1).【输入】第一行包含两个整型数据 n , k n,k n,k,以一个空格分割。第二行包含 n n n个以空格分隔的整型数据(保证有序),表示 a 1 , a 2 , … , a n ( 0 ≤ a i ≤ 100 ) a_1, a_2, \dots, a_n (0 ≤ a_i ≤ 100) a1, a2, …, an(0 ≤ ai ≤ 100)
Output
Output the number of participants who advance to the next round.【输出】输入晋级选手数
Examples
[input]
8 5
10 9 8 7 7 7 5 5
[output]
6
[input]
4 2
0 0 0 0
[output]
0
Note
- In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.第一个样例中,排名第 5 5 5的选手获得 7 7 7分,而排名第 6 6 6的选手依然是 7 7 7分,因此有六名选手突围。
- In the second example nobody got a positive score.第二个样例中,无人得分。
#include
using namespace std;
int a[51];
int main() {
// freopen("1.in", "r", stdin);
int n, k, cnt = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
auto t = a[k - 1];
for (int i = 0; i < n; i++) {
if (a[i] && t <= a[i]) cnt ++;
}
cout << cnt;
return 0;
}
You are given a rectangular board of M × N M × N M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 2 × 1 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:给定 N × M N\times M N×M的矩阵,以及无穷多的 2 × 1 2\times1 2×1大小的多米诺骨牌,允许旋转(也就是横竖放都行)。
- Each domino completely covers two squares.每张牌完全占据 2 2 2个单位面积
- No two dominoes overlap.没有重叠
- Each domino lies entirely inside the board. It is allowed to touch the edges of the board.每张骨牌都在方阵之内,贴边也算
Find the maximum number of dominoes, which can be placed under these restrictions.问在上述限制之下,最多能放多少骨牌?
Input
In a single line you are given two integers M M M and N N N — board sizes in squares ( 1 ≤ M ≤ N ≤ 16 ) (1 ≤ M ≤ N ≤ 16) (1 ≤ M ≤ N ≤ 16).【输入】一行,包含两个数 N , M N, M N,M,以空格分割
Output
Output one number — the maximal number of dominoes, which can be placed.【输出】输出一个数,表示最多放置的骨牌数
Examples
[input]
2 4
[output]
4
[input]
3 3
[output]
4
s = input().split()
print(int(s[0]) * int(s[1]) // 2)
下面给出「证明」
- 当 N , M N,M N,M不都是奇数时,有 N × M N\times M N×M为偶数,一定能分成许多 2 × X 2\times X 2×X的部分,自然可以填满区域,答案是 N × M 2 \dfrac{N\times M}{2} 2N×M
- 反之,都为奇数时,可以先填充 ( N × ( M − 1 ) 2 + ⌊ N − 1 2 ⌋ ) c y c = ⌊ N × M 2 ⌋ \Big(\dfrac{N\times (M-1)}{2}+\lfloor\dfrac{N-1}{2}\rfloor\Big)_{cyc} = \lfloor\dfrac{N\times M}{2}\rfloor\quad (2N×(M−1)+⌊2N−1⌋)cyc=⌊2N×M⌋*其中cyc表示轮换
- The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.比特大陆有一门古怪的语言「比特佳佳」
- The language is that peculiar as it has exactly one variable, called x x x. Also, there are two operations:怪就怪在,它只有一个变量 x x x,并且只有两种操作符
- Operation ++ increases the value of variable x x x by 1 1 1."++"操作符使得 x x x自增 1 1 1
- Operation – decreases the value of variable x x x by 1 1 1."–"操作符使得 x x x自减 1 1 1
- A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x x x. The statement is written without spaces, that is, it can only contain characters “+”, “-”, “X”. Executing a statement means applying the operation it contains.「比特佳佳」中的每条「语句」都是只一个包含一个变量 x x x和一个操作符的串,并且没有空格。
- A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.「比特佳佳」意义下的「程序」包含一些「语句」。
- You’re given a programme in language Bit++. The initial value of x x x is 0 0 0. Execute the programme and find its final value (the value of the variable when this programme is executed).现给定一个「比特佳佳」程序, x x x初始化为 0 0 0,问运行之后最终的 x x x是多少?
Input
The first line contains a single integer n ( 1 ≤ n ≤ 150 ) n (1 ≤ n ≤ 150) n(1 ≤ n ≤ 150) — the number of statements in the programme.Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x x x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.【输入】第一行输入一个 n n n。随后 n n n行每行包含一条「Bit++语句」,操作符与变量 X X X顺序不定,且没有空语句。
Output
Print a single integer — the final value of x x x.【输出】输出最终的 x x x的值
Examples
[input]
1
++X
[output]
1
[input]
2
X++
–X
[output]
0
#include
#include
using namespace std;
int main() {
// freopen("1.in", "r", stdin);
string str;
int x = 0;
int n; cin >> n;
while (n --) {
cin >> str;
if (str == "X++" || str == "++X") {
x ++;
} else {
x --;
}
}
cout << x;
return 0;
}
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters’ case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.按照字典序比较两个字符串,无视大小写。
Input
Each of the first two lines contains a bought string. The strings’ lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.【输入】共两行,每行包含一个包含大小写的字符串,保证长度一致。
Output
If the first string is less than the second one, print “-1”. If the second string is less than the first one, print “1”. If the strings are equal, print “0”. Note that the letters’ case is not taken into consideration when the strings are compared.【输出】如果 A A A串比 B B B串小,输出 − 1 -1 −1,一致则输出 0 0 0,否则为 1 1 1
Examples
[input]
aaaa
aaaA
[output]
0
[input]
abs
Abz
[output]
-1
[input]
abcdefg
AbCdEfF
[output]
1
Note
If you want more formal information about the lexicographical order (also known as the “dictionary order” or “alphabetical order”), you can visit the following site:想要了解「字典序」,可以点击下面的网址:
- http://en.wikipedia.org/wiki/Lexicographical_order
但是我进不去,如果你也进不去的话可以点这个百度百科_字典序
#include
#include
#include
using namespace std;
int main() {
// freopen("1.in", "r", stdin);
string a, b;
cin >> a >> b;
transform(a.begin(), a.end(), a.begin(), ::tolower);
transform(b.begin(), b.end(), b.begin(), ::tolower);
puts(a > b ? "1" : a < b ? "-1" : "0");
return 0;
}
- You’ve got a 5 × 5 5 × 5 5 × 5 matrix, consisting of 24 24 24 zeroes and a single number one. Let’s index the matrix rows by numbers from 1 1 1 to 5 5 5 from top to bottom, let’s index the matrix columns by numbers from 1 1 1 to 5 5 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:给定一个 5 × 5 5\times5 5×5 01 01 01方阵,仅含一个 1 1 1。
- Swap two neighboring matrix rows, that is, rows with indexes i i i and i + 1 i + 1 i + 1 for some integer i ( 1 ≤ i < 5 ) i (1 ≤ i < 5) i(1 ≤ i < 5).
Swap two neighboring matrix columns, that is, columns with indexes j j j and j + 1 j + 1 j + 1 for some integer j ( 1 ≤ j < 5 ) j (1 ≤ j < 5) j(1 ≤ j < 5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.你可以交换相邻两行或两列,使得 1 1 1在正中心的位置,称作「矩正」(美丽矩阵)。
Input
The input consists of five lines, each line contains five integers: the j j j-th integer in the i i i-th line of the input represents the element of the matrix that is located on the intersection of the i i i-th row and the j j j-th column. It is guaranteed that the matrix consists of 24 24 24 zeroes and a single number one.【输入】输入一个 5 × 5 5\times5 5×5的方阵
Output
Print a single integer — the minimum number of moves needed to make the matrix beautiful.【输出】输出最小操作次数使得其成为「矩正」
Examples
[input]
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
[output]
3
[input]
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
[output]
1
#include
#include
using namespace std;
int main() {
// freopen("1.in", "r", stdin);
int x, y, q;
for (int i = 1; i <= 5; ++i) {
for (int j = 1; j <= 5; ++j) {
cin >> q;
if (q) {
x = i, y = j;
break;
}
}
}
int t = abs(x -3) + abs(y - 3);
cout << t;
return 0;
}
- Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
- The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1 , 2 1, 2 1,2 and 3 3 3. Still, that isn’t enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can’t calculate sum 1 + 3 + 2 + 1 1+3+2+1 1+3+2+1 but she can calculate sums 1 + 1 + 2 1+1+2 1+1+2 and 3 + 3 3+3 3+3.老师有一些只含有 1 , 2 , 3 1,2,3 1,2,3的和式,有个小朋友只能计算算子不递减的算式。
- You’ve got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.但老师的算式不总是不递减的,现在要求你重新排序使得算子不递减。
Input
The first line contains a non-empty string s s s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters “+”. Besides, string s is a correct sum of numbers 1 , 2 1, 2 1,2 and 3 3 3. String s is at most 100 100 100 characters long.【输入】输入一个只含数字“1,2,3”和”+“的、不含空格的、非空的字符串,其长度不超过 100 100 100
Output
Print the new sum that Xenia can count.重新安排顺序使得这个小朋友能计算这个式子
Examples
[input]
3+2+1
[output]
1+2+3
[input]
1+1+3+1+3
[output]
1+1+1+3+3
[input]
2
[output]
2
s = list(input().strip().split('+'))
s.sort()
for i in range(0, len(s)- 1 ) :
print(s[i], end = "+")
print(s[len(s) - 1])
- Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
- Note, that during capitalization all the letters except the first one remains unchanged.将给定字符串的第一个字符改为大写,其余不变
Input
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 1 0 3 10^3 103.【输入】给定一个只含有大小写的非空字符串(长度不会超过 1 0 3 10^3 103)
Output
Output the given word after capitalization.【输出】输出「首字母大写」后的字符串
Examples
[input]
ApPLe
[output]
ApPLe
[input]
konjac
[output]
Konjac
toupper()
方法s = input()
print(s[0].capitalize() + s[1:])
There are n n n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.现在有排成一行的石头,具有三种不同的颜色,你可以选择将其中几块移走使得相邻两者不同色,问最少操作次数是多少?
Input
The first line contains integer n ( 1 ≤ n ≤ 50 ) n (1 ≤ n ≤ 50) n(1 ≤ n ≤ 50) — the number of stones on the table.The next line contains string s s s, which represents the colors of the stones. We’ll consider the stones in the row numbered from 1 1 1 to n n n from left to right. Then the i i i-th character s equals “R”, if the i i i-th stone is red, “G”, if it’s green and “B”, if it’s blue.【输入】第一行包含一个整型数据 n n n,随后一行包含一个字符串(长度为 n n n),字符串中的[“R”“G”“B”]分别表示红绿蓝三种颜色。Output
Print a single integer — the answer to the problem.【输出】输出一个整型数据,为满足题意的答案
Examples
[input]
3
RRG
[output]
1
[input]
5
RRRRR
[output]
4
[input]
4
BRBG
[output]
0
#include
#include
using namespace std;
string s;
int res;
int main() {
// freopen("1.in", "r", stdin);
// 因为没注释, WA 了好多次, 算是坑了自己hhh
int n; cin >> n;
cin >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == s[i - 1] && i - 1 >= 0) {
res ++;
}
}
cout << res;
return 0;
}
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif // 这样就可以避免被自己坑到啦
- Those days, many boys use beautiful girls’ photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.你的女网友在现实生活中可能是个男的!
- But yesterday, he came to see “her” in the real world and found out “she” is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users’ genders by their user names.
- This is his method: if the number of distinct characters in one’s user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.告诉你一个小妙招,凡是网名中不同字母个数是奇数的,那这个「妹子」就是男的,反之则反。
Input
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 100 100 letters.【输入】输入一个只含有小写字母的非空字符串,表示网名,至多包含 100 100 100个字母
Output
If it is a female by our hero’s method, print “CHAT WITH HER!” (without the quotes), otherwise, print “IGNORE HIM!” (without the quotes).【输出】按照这个方法,如果判定为男的就输出"IGNORE HIM!"
,否则输出"CHAT WITH HER!"
(均不含引号)
Examples
[input]
wjmzbmr
[output]
CHAT WITH HER!
[input]
xiaodao
[output]
IGNORE HIM!
[input]
sevenkplus
[output]
CHAT WITH HER!
Note
For the first example. There are 6 distinct characters in “wjmzbmr”. These characters are: “w”, “j”, “m”, “z”, “b”, “r”. So wjmzbmr is a female and you should print “CHAT WITH HER!”.
#include
#include
using namespace std;
int has[27];
int get(char ch) {
return ch - 'a';
}
int cnt;
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif
string s;
cin >> s;
for (auto i : s) {
if (has[get(i)]) {
continue;
} else {
cnt ++;
}
has[get(i)] ++;
}
puts(cnt & 1 ? "IGNORE HIM!" : "CHAT WITH HER!");
return 0;
}
- A soldier wants to buy w w w bananas in the shop. He has to pay k k k dollars for the first banana, 2 k 2k 2k dollars for the second one and so on (in other words, he has to pay i ⋅ k i·k i⋅k dollars for the i i i-th banana).
- He has n n n dollars. How many dollars does he have to borrow from his friend soldier to buy w w w bananas?士兵有$ n n n买香蕉,对于第 i i i只香蕉,需要支付$ ( i × k ) (i\times k) (i×k)。问他需要问战友借多少钱才能买 w w w只香蕉
Input
The first line contains three positive integers k , n , w ( 1 ≤ k , w ≤ 1000 , 0 ≤ n ≤ 1 0 9 ) k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 10^9) k, n, w(1 ≤ k, w ≤ 1000,0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.【输入】三个数据, k , n , w k,n,w k,n,w,意义如体面所述
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn’t have to borrow money, output 0.【输出】如果需要借钱,输出数目,否则输出 0 0 0
Examples
[input]
3 17 4
[output]
13
s = input().strip().split()
k, n, w = int(s[0]), int(s[1]), int(s[2])
S_w = (w + 1) * k * w >> 1
t = S_w - n
print("%d" % t if t > 0 else "0")
- Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.熊熊 A A A想要成为最大的熊,实在不行,那至少要比哥哥大。
- Right now, Limak and Bob weigh a a a and b b b respectively. It’s guaranteed that Limak’s weight is smaller than or equal to his brother’s weight.熊 A A A、熊 B B B的体重分别是 a , b a,b a,b,保证 a ≤ b a\le b a≤b
- Limak eats a lot and his weight is tripled after every year, while Bob’s weight is doubled after every year.熊 A A A每年体重会变成去年的 3 3 3倍,而熊 B B B则是同样意义下的 2 2 2倍。
- After how many full years will Limak become strictly larger (strictly heavier) than Bob在 n n n个年头之后,熊 A A A的体重会严格大于熊 B B B的。
Input
The only line of the input contains two integers a a a and b ( 1 ≤ a ≤ b ≤ 10 ) b (1 ≤ a ≤ b ≤ 10) b(1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.【输入】一行,包含两个整型数据 a , b a,b a,b,意义如题。
Output
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.【输出】输出一个整数,表示 n n n
Examples
[input]
4 7
[output]
2
[input]
4 9
[output]
3
[input]
1 1
[output]
1
Note
- In the first sample, Limak weighs 4 4 4 and Bob weighs 7 7 7 initially. After one year their weights are 4 ⋅ 3 = 12 4·3 = 12 4⋅3 = 12 and 7 ⋅ 2 = 14 7·2 = 14 7⋅2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn’t larger than Bob yet. After the second year weights are 36 36 36 and 28 28 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2 2 2.
- In the second sample, Limak’s and Bob’s weights in next years are: 12 12 12 and 18 18 18, then 36 36 36 and 36 36 36, and finally 108 108 108 and 72 72 72 (after three years). The answer is 3 3 3. Remember that Limak wants to be larger than Bob and he won’t be satisfied with equal weights.一样大也不行哦
- In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 3 3 and 2 2 2 then.
可以转换成两个指数函数的交点问题
有代数式 a 1 3 n = a 2 2 n ⇒ a 1 a 2 = ( 2 3 ) n ⇒ n = log 2 3 a 1 a 2 = ln ( a 1 / a 2 ) ln ( 2 / 3 ) = ln a 1 − ln a 2 ln ( 2 / 3 ) a_13^n = a_22^n\Rightarrow\dfrac{a_1}{a_2} = \Big(\dfrac{2}{3}\Big)^n\Rightarrow n = \log_{\dfrac{2}{3}}{\dfrac{a_1}{a_2}} = \dfrac{\ln(a_1/a_2)}{\ln(2/3)} = \dfrac{\ln a_1 - \ln a_2}{\ln(2/3)} a13n=a22n⇒a2a1=(32)n⇒n=log32a2a1=ln(2/3)ln(a1/a2)=ln(2/3)lna1−lna2
import math as m
s = input().strip().split()
print(int(1 + (m.log(int(s[0])) - m.log(int(s[1]))) / m.log(2/3)))
#include
#include
using namespace std;
double n, m;
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif
cin >> n >> m;
cout << int(1 + (log(n) - log(m)) / log(2.0 / 3));
return 0;
}
#include
#include
using namespace std;
int n, m;
int main() {
// freopen("1.in", "r", stdin);
int cnt = 0;
cin >> n >> m;
while (n <= m) {
n *= 3;
m <<= 1;
cnt ++;
}
cout << cnt;
return 0;
}
- Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:按照下述算法做两位数及以上的减法
- if the last digit of the number is non-zero, she decreases the number by one;最后一位非 0 0 0,减去 1 1 1
- if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).末位为 0 0 0,除以 10 10 10,也即是说去除末位
- You are given an integer number n n n. Tanya will subtract one from it k k k times. Your task is to print the result after all k k k subtractions.给定一个数 n n n,执行 k k k次这个算法
- It is guaranteed that the result will be positive integer number.数据保证答案为正数
Input
The first line of the input contains two integer numbers n n n and k ( 2 ≤ n ≤ 1 0 9 , 1 ≤ k ≤ 50 ) k (2≤n≤10^9, 1≤k≤50) k(2≤n≤109,1≤k≤50) — the number from which Tanya will subtract and the number of subtractions correspondingly.【输入】共一行,包含两个数 n , k n,k n,k,意义如题,空格分隔
Output
Print one integer number — the result of the decreasing n by one k k k times.
It is guaranteed that the result will be positive integer number.【输出】执行 k k k次这个算法,输出结果,数据保证答案为正数
Examples
[input]
512 4
[output]
50
[input]
1000000000 9
[output]
1
Note
The first example corresponds to the following sequence: 512 → 511 → 510 → 51 → 50 512→511→510→51→50 512→511→510→51→50.第一组数据对应着如下计算过程: 512 → 511 → 510 → 51 → 50 512→511→510→51→50 512→511→510→51→50
#include
using namespace std;
int n, k;
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif
cin >> n >> k;
while (k --) {
if (n % 10 == 0) {
n /= 10;
} else {
n --;
}
}
cout << n;
return 0;
}
- An elephant decided to visit his friend. It turned out that the elephant’s house is located at point 0 0 0 and his friend’s house is located at point x ( x > 0 ) x(x > 0) x(x > 0) of the coordinate line. In one step the elephant can move 1 , 2 , 3 , 4 1, 2, 3, 4 1,2,3,4 or 5 5 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend’s house.小象想从家(位置为 0 0 0)出发去找好朋友(位置为 x x x),他可以每次走 1 , 2 , 3 , 4 , 5 1,2,3,4,5 1,2,3,4,5步,求到达目的地的最小步数
Input
The first line of the input contains an integer x ( 1 ≤ x ≤ 1 000 000 ) x (1 ≤ x ≤ 1 000 000) x(1 ≤ x ≤ 1 000 000) — The coordinate of the friend’s house.【输入】输入一个数 x x x,意义如题
Output
Print the minimum number of steps that elephant needs to make to get from point 0 0 0 to point x x x.【输出】在一行中输出最小步数
Examples
[input]
5
[output]
1
[input]
12
[output]
3
Note
- In the first sample the elephant needs to make one step of length 5 to reach the point x.在第一个样例中,一步抵达目的地。
- In the second sample the elephant can get to point x if he moves by 3 , 5 3, 5 3,5 and 4 4 4. There are other ways to get the optimal answer but the elephant cannot reach x x x in less than three moves.第二个样例中,可能的走法是"3,5,4"。存在其他走法,但可以证明不会步数少于 3 3 3。
n = int(input())
print(1 + (n // 5) if n % 5 != 0 else n // 5)
- Linear Kingdom has exactly one tram line. It has n n n stops, numbered from 1 1 1 to n n n in the order of tram’s movement. At the i i i-th stop a i a_i ai passengers exit the tram, while b i b_i bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
- Your task is to calculate the tram’s minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.一条线路上人来人往,请你计算车容量至少为多少(规定先下后上)。
Input
The first line contains a single number n ( 2 ≤ n ≤ 1000 ) n (2 ≤ n ≤ 1000) n(2 ≤ n ≤ 1000) — the number of the tram’s stops.
Then n n n lines follow, each contains two integers a i a_i ai and b i ( 0 ≤ a i , b i ≤ 1000 ) b_i (0 ≤ a_i, b_i ≤ 1000) bi(0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i i i-th stop, and the number of passengers that enter the tram at the i i i-th stop. The stops are given from the first to the last stop in the order of tram’s movement.
The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, ∀ ( 1 ≤ i ≤ n ) : ∑ j = 1 i − 1 b j − ∑ j = 1 i − 1 a j ≥ a i . \forall(1\le i\le n):\sum_{j=1}^{i-1}b_j - \sum_{j=1}^{i-1}a_j\ge a_i. ∀(1≤i≤n):∑j=1i−1bj−∑j=1i−1aj≥ai.This particularly means that a 1 = 0 a_1 = 0 a1 = 0.
At the last stop, all the passengers exit the tram and it becomes empty. More formally, ∑ j = 1 n − 1 b j − ∑ j = 1 n − 1 = a n . \sum_{j=1}^{n-1}b_j - \sum_{j=1}^{n-1} = a_n. ∑j=1n−1bj−∑j=1n−1=an. No passenger will enter the train at the last stop. That is, b n = 0 b_n = 0 bn = 0.【输入】首先输入一个整型数据 n n n,表示站台数目,随后 n n n行每行有两个数,分别表示下车与上车人数。特殊地,对于起点站无人下车,终点站无人上车
Output
Print a single integer denoting the minimum possible capacity of the tram ( 0 0 0 is allowed).【输出】输出最大车容量
Examples
input
4
0 3
2 5
4 2
4 0
output
6
Note
- For the first example, a capacity of 6 6 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0 0 0. Then, 3 3 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
- At the second stop, 2 2 2 passengers exit the tram ( 1 1 1 passenger remains inside). Then, 5 5 5 passengers enter the tram. There are 6 6 6 passengers inside the tram now.
- At the third stop, 4 4 4 passengers exit the tram ( 2 2 2 passengers remain inside). Then, 2 2 2 passengers enter the tram. There are 4 4 4 passengers inside the tram now.
- Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
- Since the number of passengers inside the tram never exceeds 6 6 6, a capacity of 6 6 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6 6 6. Hence, 6 6 6 is the correct answer.
#include
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
#endif
int n, out, in, cap = 0, ans = -1;
cin >> n;
while (n --) {
cin >> out >> in;
cap -= out;
cap += in;
ans = max(ans, cap);
}
cout << ans;
return 0;
}
- Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That’s why he decided to invent an extension for his favorite browser that would change the letters’ register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.强迫症表示单词只有大写字母才像样,只有小写字母也行但作为懒癌患者,会尽可能地减少修改次数。比如说"ViP"中大写字母多,我们就改成大写字母"VIP".
Input
The first line contains a word s s s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 1 1 to 100 100 100.【输入】输入一个字符串,长度 ∈ [ 1 , 100 ] \in[1,100] ∈[1,100]
Output
Print the corrected word s s s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.【输出】大写字母多的话就输出全大写,否则输出全小写,特殊地对于数目相同,选择小写字母
Examples
[input]
HoUse
[output]
house
[input]
ViP
[output]
VIP
[input]
maTRIx
[output]
matrix
import string as str
s = input().strip()
cnt1 = 0
for i in range(0, len(s)) :
if s[i] in str.ascii_lowercase :
cnt1 += 1
s = s.upper() if len(s) > 2 * cnt1 else s.lower()
print(s)
- During the break the schoolchildren, boys and girls, formed a queue of n n n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.是这样的,有 n n n个小朋友排队。
- Let’s describe the process more precisely. Let’s say that the positions in the queue are sequentially numbered by integers from 1 1 1 to n n n, at that the person in the position number 1 1 1 is served first. Then, if at time x x x a boy stands on the i i i-th position and a girl stands on the ( i + 1 ) (i + 1) (i + 1)-th position, then at time x + 1 x + 1 x + 1 the i i i-th position will have a girl and the ( i + 1 ) (i +1 ) (i +1)-th position will have a boy. The time is given in seconds.但是男孩子嘛,让着女士比较绅士,所以每过 1 1 1个单位时间,男孩就和他后面的女士换个位置(相邻)。(原文是说,男孩比较羞涩,容易尴尬。于是想要换位置,这里我改变了语境,应该也能接受hhh)
- You’ve got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t t t seconds.问过了 k k k时间后的队伍如何
Input
The first line contains two integers n n n and t ( 1 ≤ n , t ≤ 50 ) t (1 ≤ n, t ≤ 50) t(1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.The next line contains string s s s, which represents the schoolchildren’s initial arrangement. If the i i i-th position in the queue contains a boy, then the i i i-th character of string s s s equals “B”, otherwise the i i i-th character equals “G”.【输入】第一行输入两个整型数据 n , k n,k n,k表示队伍长度,以及过了多少时间。随后一行输入一个字符串,"B,G"分别表示一位绅士和一位女士。
Output
Print string a a a, which describes the arrangement after t t t seconds. If the i i i-th position has a boy after the needed time, then the i i i-th character a must equal “B”, otherwise it must equal “G”.【输出】输出一个字符串表示最终的队列
Examples
[input]
5 1
BGGBG
[output]
GBGGB
[input]
5 2
BGGBG
[output]
GGBGB
[input]
4 1
GGGB
[output]
GGGB
BGG
的情况BG
为GB
即可a = input().strip().split()
n, k = int(a[0]), int(a[1])
s = input().strip()
while k != 0 :
s = s.replace("BG", "GB")
k -= 1
print(s)
- Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 4 4 and 7 7 7. For example, numbers 47 , 744 , 4 47, 744, 4 47,744,4 are lucky and 5 5 5, 17 17 17, 467 467 467 are not.众所周知,只含有 4 4 4和 7 7 7的数字被称作幸运数字
- Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.不幸的是,并非所有数字都是幸运的。一个数字是「类幸运数字」,当且仅当其中的幸运数字个数是 4 , 7 4,7 4,7个
Input
The only line contains an integer n ( 1 ≤ n ≤ 1 0 18 ) n (1 ≤ n ≤ 10^{18}) n(1 ≤ n ≤ 1018).【输入】仅含一个数字 n n nPlease do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.【输入提示】C++选手最好使用
cin
,否则对于占位符,你应当使用%I64d
,而不是%lld
Output
Print on the single line “YES” if n is a nearly lucky number. Otherwise, print “NO” (without the quotes).【输出】如果这个数字是幸运数字,输出"YES",否则输出"NO"
Examples
[Input]
40047
[Output]
NO
[Input]
7747774
[Output]
YES
[Input]
1000000000000000000
[Output]
NO
Note
- In the first sample there are 3 lucky digits (first one and last two), so the answer is “NO”.第一组数据只含有 3 3 3个幸运数字,因此不是「类幸运数字」
- In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is “YES”.第二组数据包含 7 7 7个幸运数字,因此是「类幸运数字」
- In the third sample there are no lucky digits, so the answer is “NO”.第三组数据中没有幸运数字,因此不是类幸运数字
import collections
s = list(input().strip())
ok = True
cnt = collections.Counter(s)
if (cnt['4'] + cnt['7'] not in [4, 7]):
ok = False
print("YES" if ok == True else "NO")
- The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it’s easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.我们称「翻」译成功,当且仅当原话与译话刚好为倒置关系
Input
The first line contains word s s s, the second line contains word t t t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 100 100 symbols.【输入】输入是两个只含小写英文字母的、长度不超过 100 100 100的、不含空格的字符串 t , s t,s t,s,各占一行
Output
If the word t t t is a word s s s, written reversely, print YES, otherwise print NO.【输出】如果 t t t是 s s s的倒置,输出"YES",否则输出"NO"
Examples
[Input]
code
edoc
[Output]
YES
[Input]
abb
aba
[Output]
NO
[Input]
code
code
[Output]
NO
a[::-1]
a, b = input().strip(), input().strip()
print("YES" if a[::-1] == b else "NO")
- Anton likes to play chess, and so does his friend Danik.
- Once they have played n n n games in a row. For each game it’s known who was the winner — Anton or Danik. None of the games ended with a tie.
- Now Anton wonders, who won more games, he or Danik? Help him determine this.现有两位棋手对弈,每局都没有和局。已经下了 n n n场,问谁赢得多
Input
The first line of the input contains a single integer n ( 1 ≤ n ≤ 100 000 ) n (1 ≤ n ≤ 100 000) n(1 ≤ n ≤ 100 000) — the number of games played.
The second line contains a string s s s, consisting of n uppercase English letters ‘A’ and ‘D’ — the outcome of each of the games. The i i i-th character of the string is equal to ‘A’ if the Anton won the i i i-th game and ‘D’ if Danik won the i i i-th game.【输入】共两行,第一行包含一个整型数据 n n n,表示对弈局数,第二行包含一个字符串 s s s,大写字母 A , D A,D A,D分别表示 A n t o n \rm Anton Anton, D a n i k \rm Danik Danik获得了胜利
Output
If Anton won more games than Danik, print “Anton” (without quotes) in the only line of the output.
If Danik won more games than Anton, print “Danik” (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print “Friendship” (without quotes).【输出】如果 A n t o n \rm Anton Anton赢的更多,输出"Anton";如果 D a n i k \rm Danik Danik赢的更多,输出"Danik";一样多则输出"Friengship"。
Examples
[Input]
6
ADAAAA
[Output]
Anton
[Input]
7
DDDAADA
[Output]
Danik
[Input]
6
DADADA
[Output]
Friendship
Note
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is “Anton”.
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is “Danik”.
In the third sample, both Anton and Danik won 3 games and the answer is “Friendship”.
C/Cxx/Java
可以使用嵌套的三目运算符A ? a : B ? b : c
import collections
n = input()
s = input().strip()
cnt = collections.Counter(s)
if cnt['A'] == cnt['D']:
print("Friendship")
elif cnt['A'] > cnt['D']:
print("Anton")
else:
print("Danik")