A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, m is the number of the participants of the current round):
let k be the maximal power of the number 2 such that k ≤ m,
k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
when only one participant remains, the tournament finishes.
Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it’s a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input
The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.
Output
Print two integers x and y — the number of bottles and towels need for the tournament.
input
5 2 3
output
20 15
input
8 2 4
output
35 32
题目链接:cf-628A
题目大意:有n个人进行网球比赛,毛巾是每人一条,每场比赛,给每位参加比赛的选手发b瓶水以及裁判发1瓶水。问需要多少瓶水,多少条毛巾。
题目思路: eg: 网球两个人一场赛,所以第一次要4人比2场,每场是2*2+1瓶水,有一个人轮空,所以是10瓶水。第二场是3个人,选其中两个人比一场,又是5瓶水,第三场是两个人,比一场,又是5瓶水。 注意: 每场比赛人数要是最大的2的倍数
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
int main(){
int n,b,p;
cin >> n >> b >> p;
int towel = p * n;
int water = 0;
while(n > 1)
{
for (int i = 0; i <= 10; i++)
{
if ((int)pow(2,i) > n)
{
water += pow(2,i - 1) * b + pow(2,i - 1) / 2;
n = n - pow(2,i - 1) / 2;
break;
}
}
}
cout << water << " " << towel << endl;
return 0;
}
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.
You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.
A substring of a string is a nonempty sequence of consecutive characters.
For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.
Output
Print integer a — the number of substrings of the string s that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
input
124
output
4
input
04
output
3
input
5810438174
output
9
题目链接:cf-628B
题目大意:给出一个n长度的字符串,问这个数字串的子串中能整除4的子串数(子串可以包括前置0) 有多少个
题目思路:简单dp。
能被4整除的数,个位和十位所组成的两位数能被4整除,那么这个数能被4整除
另外需要处理,个位能被4整除的情况。
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
ll dp[400000];
int main(){
string s;
cin >> s;
if ((s[0] - '0') % 4 == 0) dp[0]++;
for (int i = 1; i < s.size(); i++)
{
int tmp = (s[i - 1] - '0') * 10 + (s[i] - '0');
if (tmp % 4 == 0) dp[i] = dp[i - 1] + i;
else dp[i] = dp[i - 1];
if ((s[i] - '0') % 4 == 0) dp[i]++;
}
cout << dp[s.size() - 1] << endl;
return 0;
}
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .
Limak gives you a nice string s and an integer k. He challenges you to find any nice string s’ that . Find any s’ satisfying the given conditions, or print “-1” if it’s impossible to do so.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input
The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 106).
The second line contains a string s of length n, consisting of lowercase English letters.
Output
If there is no string satisfying the given conditions then print “-1” (without the quotes).
Otherwise, print any nice string s’ that .
input
4 26
bear
output
roar
input
2 7
af
output
db
input
3 1000
hey
output
-1
题目链接:cf-628C
题目大意:n长度的字符串,构造一个字符串的差值和原串相差k。
差值计算eg:
题目思路:我刚开始写,直往大的地方想,比如b,那就往z方向构造。其实还可以往a方向构造
以下是代码:
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof (a))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define INF 1e9
#define eps 1e-10
using namespace std;
typedef long long ll;
int main(){
int n,k;
cin >> n >> k;
string s;
cin >> s;
for (int i = 0; i < n; i++)
{
int tmp = 'z' - s[i];
int tmp2 = s[i] - 'a';
int maxn = max(tmp,tmp2);
if (maxn >= k)
{
if (tmp > tmp2) s[i] = s[i] + k;
else s[i] -= k;
k = 0;
break;
}
else
{
if (tmp > tmp2) s[i] = 'z';
else s[i] = 'a';
k -= maxn;
}
}
if (k > 0) cout << -1 << endl;
else cout << s << endl;
return 0;
}