Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)

A. Tritonic Iridescence

题解:分类讨论。注意题目要求,至少有两种方案。

 1 #pragma warning(disable:4996)
 2 #include<cstdio>
 3 #include<string>
 4 #include<cstring>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8
 9 int n, m;
10 string s;
11
12 int main()
13 {
14     while (cin >> n) {
15         cin >> s;
16         int cnt = 0;
17         for (int i = 0; i < n; i++) if (s[i] == ‘?‘) cnt++;
18         if (!cnt) printf("No\n");
19         else {
20             bool flag1 = false;
21             bool flag2 = true;
22             for (int i = 1; i < n; i++) {
23                 if (s[i] == s[i - 1] && s[i] == ‘?‘) flag1 = true;
24                 if (s[i] == s[i - 1] && s[i] != ‘?‘) flag2 = false;
25             }
26             if (!flag2) printf("No\n");
27             else {
28                 if (flag1) printf("Yes\n");
29                 else {
30                     bool flag3 = false;
31                     for (int i = 1; i < n - 1; i++) {
32                         if (s[i] == ‘?‘) {
33                             if (s[i - 1] == s[i + 1]) flag3 = true;
34                         }
35                     }
36                     if (s[0] == ‘?‘ || s[n - 1] == ‘?‘) flag3 = true;
37                     if (!flag3) printf("No\n");
38                     else printf("Yes\n");
39                 }
40             }
41         }
42     }
43     return 0;
44 }

B. Mystical Mosaic

题解:对于同一列的"#"所在行应该是对称的。

 1 #pragma warning(disable:4996)
 2 #include<map>
 3 #include<vector>
 4 #include<stack>
 5 #include<queue>
 6 #include<cstdio>
 7 #include<string>
 8 #include<cstring>
 9 #include<iostream>
10 #include<algorithm>
11 using namespace std;
12
13 const int maxn = 60;
14
15 int n, m;
16 int mp[maxn][maxn];
17
18 int main()
19 {
20     scanf("%d%d", &n, &m);
21     getchar();
22     for (int i = 1; i <= n; i++) {
23         for (int j = 1; j <= m; j++)
24             mp[i][j] = (getchar() == ‘#‘);
25         getchar();
26     }
27     for (int i = 1; i <= n; i++) {
28         for (int j = i + 1; j <= n; j++) {
29             bool flag1 = true, flag2 = true;
30             for (int k = 1; k <= m; k++) {
31                 if (mp[i][k] != mp[j][k]) flag1 = false;
32                 if (mp[i][k] && mp[j][k]) flag2 = false;
33             }
34             if (!flag1 && !flag2) { puts("No"); return 0; }
35         }
36     }
37     puts("Yes"); return 0;
38 }

C. Three-level Laser

题解:分析式子,当 Ej  选定后,i=j-1,所以只需要考虑 Ek ,显然 k 的位置离 j 越远答案越优。

注意:精度。

 1 #pragma warning(disable:4996)
 2 #include<map>
 3 #include<queue>
 4 #include<string>
 5 #include<vector>
 6 #include<cstdio>
 7 #include<cstring>
 8 #include<iostream>
 9 #include<algorithm>
10 using namespace std;
11 typedef long long ll;
12
13 const int maxn = 1e5 + 5;
14
15
16 int n, U;
17 int a[maxn];
18
19 int main()
20 {
21     while (scanf("%d%d", &n, &U) != EOF) {
22         for (int i = 1; i <= n; i++) scanf("%d", a + i);
23         double ans = 0;
24         for (int i = 2; i < n; i++) {
25             int p = lower_bound(a + 1, a + n + 1, a[i - 1] + U) - (a);
26
27             if (a[p] != a[i - 1] + U) p--;
28             if (p == i) continue;
29
30             double tp = 1.0*(a[p] - a[i]) / (a[p] - a[i - 1]);
31             ans = max(ans, tp);
32         }
33         if (!ans) printf("-1\n");
34         else printf("%.12lf\n", ans);
35     }
36     return 0;
37 }

原文地址:https://www.cnblogs.com/zgglj-com/p/8684750.html

时间: 2024-10-10 05:43:18

Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)的相关文章

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记

题目链接:C. Producing Snow 题意:给两个数组v[N],T[N],v[i]表示第i天造的雪,T[i],表示第i天的温度,一堆雪如果<=T[i],当天就会融完,否则融化T[i],要求输出每天的融雪总量. 题解:我对T数组求个前缀和,就可以二分找到每堆雪在那一天(pos)融化,余下的要加进答案中ans[i],然后用一个an数组在a[i]+1,a[pos]-1,最后求再求一次前缀和. ans[i]再加上an[i]*t[i].每次操作二分logn,N次操作.复杂度O(nlogn) #in

Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) C. Stairs and Elevators【二分查找】

In the year of 30XX30XX participants of some world programming championship live in a single large hotel. The hotel has nn floors. Each floor has mm sections with a single corridor connecting all of them. The sections are enumerated from 11 to mm alo

【枚举】【二分】【推导】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求.给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务. 对服务器按能提供的资源从小到大排序.枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的

【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是,我们现在只需要统计sigma((L+f(L,K))),最后除以K即可. 统计sigma(L)时,我们考虑计算每条边出现在了几条路径中,设u为edgei的子节点,那么这条边对答案的贡献就是siz(u)*(n-siz(u)),siz(u)为u的子树大小. 统计sigma(f(L,K))时,我们需要dp出

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B

Description Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends.

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

Description In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) A

Description Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) B. T-Shirt Hunt

B. T-Shirt Hunt time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participant

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) E. Prairie Partition 二分+贪心

E. Prairie Partition It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x. For example, the p