首页 > 代码库 > Codeforces Round #379 (Div. 2)

Codeforces Round #379 (Div. 2)

A. Anton and Danik

Anton likes to play chess, and so does his friend Danik.

Once they have played 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.

Input

The first line of the input contains a single integer n (1?≤?n?≤?100?000) — the number of games played.

The second line contains a string s, consisting of n uppercase English letters ‘A‘ and ‘D‘ — the outcome of each of the games. The i-th character of the string is equal to ‘A‘ if the Anton won the i-th game and ‘D‘ if Danik won the i-th game.

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多还是D多,亦或者是一样多的水题。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 signed main(void)
 5 {
 6     int n; cin >> n;
 7     string s; cin >> s;
 8     
 9     int t = 0;
10     
11     for (auto i : s)
12         if (i == A)
13             ++t;
14         else
15             --t;
16     
17     if (!t)
18         cout << "Friendship" << endl;
19     else if (t > 0)
20         cout << "Anton" << endl;
21     else
22         cout << "Danik" << endl;
23 }
A.cpp

 

B. Anton and Digits

Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.

Anton‘s favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!

Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.

Input

The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0?≤?k2,?k3,?k5,?k6?≤?5·106).

Output

Print one integer — maximum possible sum of Anton‘s favorite integers that can be composed using digits from the box.

 

问用k2个2,k3个3,k5个5,k6个6,能组合出的32和256中最大的和。

贪心地优先组合256,然后尽可能多地组合32即可。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 signed main(void)
 5 {
 6     int a, b, c, d, t, ans;
 7     cin >> a >> b >> c >> d;
 8     
 9     t = min(a, min(c, d));
10     ans = t * 256;
11     a -= t;
12     t = min(a, b);
13     ans += t * 32;
14     cout << ans << endl;
15 }
B.cpp

 

C. Anton and Making Potions

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions.

Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.

  1. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
  2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.

Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.

Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.

Input

The first line of the input contains three integers nmk (1?≤?n?≤?2·109,?1?≤?m,?k?≤?2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.

The second line of the input contains two integers x and s (2?≤?x?≤?2·109,?1?≤?s?≤?2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.

The third line contains m integers ai (1?≤?ai?<?x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.

The fourth line contains m integers bi (1?≤?bi?≤?2·109) — the number of manapoints to use the i-th spell of the first type.

There are k integers ci (1?≤?ci?≤?n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It‘s guaranteed that ci are not decreasing, i.e. ci?≤?cj if i?<?j.

The sixth line contains k integers di (1?≤?di?≤?2·109) — the number of manapoints required to use the i-th spell of the second type. It‘s guaranteed that di are not decreasing, i.e. di?≤?dj if i?<?j.

Output

Print one integer — the minimum time one has to spent in order to prepare n potions.

 

需要制造n瓶毒药(也许是饮料,不知道),制造一瓶需要x单位时间。现在有2类魔法,每类最多只能使用一种且一次。

魔法一:有m种,花费bi金钱,使得制造一瓶毒药的时间变成ai。

魔法二:有k种,花费di金钱,使得在0单位时间内制造ci瓶毒药。

先给出最多花费金钱,求最小完成时间。

 

对于每种魔法,按照花费从小到大排序后,花费大而效果差的一定没用,直接忽略即可。

筛出两个按照花费单调上升的魔法序列,从左向右枚举一种魔法的时候,根据最大金钱的限制,另一种魔法对应的最优决策一定是从右向左,维护两个指针即可。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 200005
 5 #define int long long
 6 
 7 typedef long long LL;
 8 typedef pair<int, int> pr;
 9 
10 int n, m, k, c, s;
11 
12 pr sp1[N]; int t1;
13 pr sp2[N]; int t2;
14 
15 signed main(void)
16 {
17     cin >> n >> m >> k >> c >> s;
18     
19     for (int i = 1; i <= m; ++i)
20         cin >> sp1[i].second;
21         
22     for (int i = 1; i <= m; ++i)
23         cin >> sp1[i].first;
24         
25     for (int i = 1; i <= k; ++i)
26         cin >> sp2[i].second;
27     
28     for (int i = 1; i <= k; ++i)
29         cin >> sp2[i].first;
30         
31     sp1[++m] = make_pair(0, c);
32     sp2[++k] = make_pair(0, 0);
33         
34     sort(sp1 + 1, sp1 + 1 + m);
35     sort(sp2 + 1, sp2 + 1 + k);
36     
37     t1 = t2 = 0;
38     
39     for (int i = 1; i <= m; ++i)if (sp1[i].first <= s)
40         if (!t1 || sp1[i].second < sp1[t1].second)sp1[++t1] = sp1[i];
41             
42     for (int i = 1; i <= k; ++i)if (sp2[i].first <= s)
43         if (!t2 || sp2[i].second > sp2[t2].second)sp2[++t2] = sp2[i];
44         
45     if (sp1[t1].second <= 0)return puts("0"), 0;
46     if (sp2[t2].second >= n)return puts("0"), 0;
47     
48     LL answer = 4e18 + 7;
49     
50     for (int i = 1, j = t1; i <= t2; ++i)
51     {
52         while (j && sp1[j].first + sp2[i].first > s)--j;
53             
54         if (j)answer = min(answer, (LL)sp1[j].second * (n - sp2[i].second));
55     }
56     
57     cout << answer << endl;
58 }
C.cpp

 

D. Anton and Chess

Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.

The first task he faced is to check whether the king is in check. Anton doesn‘t know how to implement this so he asks you to help.

Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.

Help Anton and write the program that for the given position determines whether the white king is in check.

Remainder, on how do chess pieces move:

  • Bishop moves any number of cells diagonally, but it can‘t "leap" over the occupied cells.
  • Rook moves any number of cells horizontally or vertically, but it also can‘t "leap" over the occupied cells.
  • Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can‘t "leap".
Input

The first line of the input contains a single integer n (1?≤?n?≤?500?000) — the number of black pieces.

The second line contains two integers x0 and y0 (?-?109?≤?x0,?y0?≤?109) — coordinates of the white king.

Then follow n lines, each of them contains a character and two integers xi and yi (?-?109?≤?xi,?yi?≤?109) — type of the i-th piece and its position. Character ‘B‘ stands for the bishop, ‘R‘ for the rook and ‘Q‘ for the queen. It‘s guaranteed that no two pieces occupy the same position.

Output

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.

 

在无限大的国际象棋棋盘上,给出白子King的位置,以及一些黑子的种类(后,车,象)和位置,求是否in check。注意棋子不能 越“子”强杀。

 

枚举王的8个方向,看最近的棋子是否符合这个方向即可。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 500005
 5 #define inf 2e9 + 7
 6 
 7 int n;
 8 int tx;
 9 int ty;
10 int vis[8];
11 int dis[8];
12 
13 signed main(void)
14 {
15     cin >> n >> tx >> ty;
16     
17     for (int i = 0; i < 8; ++i)
18         dis[i] = inf;
19     
20     for (int i = 1; i <= n; ++i)
21     {
22         char c; int x, y; 
23         cin >> c >> x >> y;
24 
25         if (x == tx && y < ty && ty - y < dis[0])
26             dis[0] = ty - y, vis[0] = (c == Q || c == R);
27         if (x == tx && y > ty && y - ty < dis[1])
28             dis[1] = y - ty, vis[1] = (c == Q || c == R);
29         if (y == ty && x < tx && tx - x < dis[2])
30             dis[2] = tx - x, vis[2] = (c == Q || c == R);
31         if (y == ty && x > tx && x - tx < dis[3])
32             dis[3] = x - tx, vis[3] = (c == Q || c == R);
33             
34         if (tx + ty == x + y && x < tx && tx - x < dis[4])
35             dis[4] = tx - x, vis[4] = (c == Q || c == B);
36         if (tx + ty == x + y && x > tx && x - tx < dis[5])
37             dis[5] = x - tx, vis[5] = (c == Q || c == B);
38         if (tx - ty == x - y && x < tx && tx - x < dis[6])
39             dis[6] = tx - x, vis[6] = (c == Q || c == B);
40         if (tx - ty == x - y && x > tx && x - tx < dis[7])
41             dis[7] = x - tx, vis[7] = (c == Q || c == B);
42     }
43     
44     int answer = 0;
45     
46     for (int i = 0; i < 8; ++i)
47         answer |= vis[i];
48         
49     puts(answer ? "YES" : "NO");
50 }
D.cpp

 

后记:貌似这次CF的题都很友(水)好(水)。

 

@Author: YouSiki

Codeforces Round #379 (Div. 2)