KEYENCE Programming Contest 2019 Solution

A - Beginning

签到.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int a[4];
 7     while (scanf("%d", a) != EOF)
 8     {
 9         for (int i = 1; i < 4; ++i) scanf("%d", a + i);
10         sort(a, a + 4);
11         int res = 0;
12         for (int i = 0; i < 4; ++i) res = res * 10 + a[i];
13         puts(res == 1479 ? "YES" : "NO");
14     }
15     return 0;
16 }
View Code

B - KEYENCE String

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 string s;
 5 
 6 string get(int pos)
 7 {
 8     string res = "";
 9     for (int i = 0; i <= pos; ++i) res += s[i];
10     int len = s.size();
11     for (int i = len - (7 - pos - 1); i < len; ++i) res += s[i];
12     return res;
13 }
14 
15 bool work()
16 {
17     for (int i = 0; i < 7; ++i)
18     {
19         string tmp = get(i);
20         if (tmp == "keyence") return 1;
21     }
22     return 0;
23 }
24 
25 int main()
26 {
27     while (cin >> s) puts(work() ? "YES" : "NO");
28     return 0;
29 }
View Code

C - Exam and Wizard

Solved.

题意:

给出些个数字$A_i, 和 B_i$

要求构造$C_i 使得 C_i >= B_i 并且 \sum A_i = \sum C_i$

并且使得变动的数字个数最少

思路:

先弄出不足的部分,然后取差值最大的$A_i > B_i$ 的部分用堆维护,每次取最大的贡献出来补充

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 100010
 5 #define ll long long
 6 int n, a[N], b[N];
 7 
 8 int main()
 9 {
10     while (scanf("%d", &n) != EOF)
11     {
12         for (int i = 1; i <= n; ++i) scanf("%d", a + i);
13         for (int i = 1; i <= n; ++i) scanf("%d", b + i);
14         ll need = 0;
15         priority_queue <int, vector <int>, less <int> > pq;
16         int res = 0; 
17         for (int i = 1; i <= n; ++i) 
18         {
19             if (b[i] > a[i]) need += b[i] - a[i], ++res;
20             else if (b[i] < a[i]) pq.push(a[i] - b[i]);
21         }
22         while (!pq.empty() && need > 0)
23         {
24             int top = pq.top(); pq.pop();
25             need -= top; ++res;    
26         }
27         if (need > 0) puts("-1");
28         else printf("%d\n", res);
29     }
30     return 0;
31 }
View Code

E - Connecting Cities

Unsolved.

题意:

$n个城市,两个城市之间的边权是 |i - j| \cdot D + A_i + A_j$

求最小生成树

猜你喜欢

转载自www.cnblogs.com/Dup4/p/10265066.html