A-Watermelon CodeForces
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 kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
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.
输入:
The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.
输出:
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.
样例输入:
1 | 8 |
样例输出:
1 | YES |
NOTE:For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
大体意思就是输入一个数 看它能不能拆分成两个偶数 不要求两个偶数大小相同.
代码如下:
1 | #include <bits/stdc++.h> |
B - Theatre Square
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city’s anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It’s allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It’s not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
输入:
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
输出:
Write the needed number of flagstones.
样例输入:
1 | 6 6 4 |
样例输出:
1 | 4 |
大体意思就是给你一个n乘m的面积 再给你一个a乘a的方形地板 求最少需要多少块才可以完全覆盖
思路:求出长需要的块数 求出宽需要的块数 相乘即可
代码如下:
1 | #include <bits/stdc++.h> |
C - IQ test
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.
输入:
The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
输出:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
样例输入:
1 | 5 |
样例输出:
1 | 3 |
样例输入:
1 | 4 |
样例输出:
1 | 2 |
大体意思就是输入一个数 仅包含一个偶数或者奇数 求出该数的位置
优化后的代码如下:
1 | #include <bits/stdc++.h> |
D - Vanya and Lanterns
Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?
输入:
The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.
The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
输出:
Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn’t exceed 10 - 9.
样例输入:
1 | 7 15 |
样例输出:
1 | 2.5000000000 |
样例输入:
1 | 2 5 |
样例输出:
1 | 2.0000000000 |
Note:Consider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
大体意思就是给你一段道路的长度,每个路灯所在位置,求路灯所至少要照亮的范围,才可保证所有路灯能照亮这段道路
注意:路灯的第一个位置或者最后一个位置可能不在道路两边.
我的代码如下:
1 | #include <bits/stdc++.h> |
优化后的代码:
1 | #include <bits/stdc++.h> |
E - Registration system
A new e-mail service “Berlandesk” is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that’s why they ask you to help. You’re suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, …), among these numbers the least i is found so that namei does not yet exist in the database.
输入:
The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
输出:
Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
样例输入:
1 | 4 |
样例输出:
1 | OK |
样例输入:
1 | 6 |
样例输出:
1 | OK |
大体意思就是输入一个字符串 如果是第一次输入 直接输出该字符串 否则的话 将该字符串重命名输出 即在字符串后面加上序号 从1开始
思路:用结构体解题 存字符串和出现的次数
我的代码如下:
1 | #include <bits/stdc++.h> |
优化的代码:
1 | #include <bits/stdc++.h> |
F - Cut Ribbon
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:
After the cutting each ribbon piece should have length a, b or c.
After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
输入:
The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.
输出:
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
样例输入:
1 | 5 5 3 2 |
样例输出:
1 | 2 |
样例输入:
1 | 7 5 5 2 |
样例输出:
1 | 2 |
大体意思就是给你一个长色带 给出三个切割长度 求最多可以切割成几段
代码如下:
1 | 暂无代码 |
G - T-primes
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we’ll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Т-prime or not..
输入:
The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
输出:
Print n lines: the i-th line should contain “YES” (without the quotes), if number xi is Т-prime, and “NO” (without the quotes), if it isn’t.
样例输入:
1 | 3 |
样例输出:
1 | YES |
大体意思就是给你一堆数 然后求出这些数中因子为三个的数
代码如下:
1 | #include <bits/stdc++.h> |
H - Cheap Travel
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
输入:
The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
输出:
Print a single integer — the minimum sum in rubles that Ann will need to spend.
样例输入:
1 | 6 2 1 2 |
样例输出:
1 | 6 |
样例输入:
1 | 5 2 2 3 |
样例输出:
1 | 8 |
大体意思就是给你一段路程 有每公里的票p 和每m公里的票价mp,求出经过该段路程所需要的费用最小为多少.
注意:该题有坑 mp不一定小于m乘p 如果mp小的话 注意最后的余数乘p和mp比较
代码如下:
1 | #include <bits/stdc++.h> |