[关闭]
@Dmaxiya 2018-08-17T10:16:19.000000Z 字数 4439 阅读 1060

Codeforces Round #472 (Div. 1)

Codeforces


Contests 链接:Codeforces Round #472 (Div. 1)
过题数:3
排名:253/1066

A. Mystical Mosaic

题意

最初有一个 的网格,每个方格的颜色最初都是白色的,每次操作可以选择一些行与一些列,将这些行和列的交点上的方格都涂上黑色,每一个行与列在所有操作中只能被选择一次,给定最终的网格,问能否通过有限次合法的操作得到最终网格。

输入

第一行包括两个整数 ,接下去 行每行为一个长度为 的字符串,字符串只包含 .#. 表示最终该方格颜色为白色,# 表示最终该方格为黑色。

输出

如果可以通过有限次合法的操作得到最终的网格,就输出 ,否则输出 ,大小写任意。

样例

输入
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
输出
Yes
提示
该网格可以通过以下三次操作得到:

输入
5 5
..#..
..#..
#####
..#..
..#..
输出
No
提示
为了得到中间的一行,第一次操作必须选择第 行与所有列,这样其它列在后面的操作中就无法再被选择,因此其他行的黑色方块就无法被涂上黑色。
输入
5 9
........#
#........
..##.#...
.......#.
....#.#.#
输出
No

题解

可以发现,在一次操作中,所有被操作行得到的字符串都是完全相同的,因此我们可以将所有字符串都放入到一个 中,在已经被去重的所有字符串中,同一列只能出现最多一个黑色方格,如果出现多于 个的黑色网格,则说明两次操作选择了同一列。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 100;
  21. int n, m;
  22. string str[maxn];
  23. string tmp;
  24. set<string> st;
  25. set<string>::iterator it;
  26. int cnt[maxn];
  27. int main() {
  28. #ifdef LOCAL
  29. freopen("test.txt", "r", stdin);
  30. // freopen("test1.out", "w", stdout);
  31. #endif // LOCAL
  32. ios::sync_with_stdio(false);
  33. while(cin >> n >> m) {
  34. st.clear();
  35. memset(cnt, 0, sizeof(cnt));
  36. for(int i = 0; i < n; ++i) {
  37. cin >> str[i];
  38. st.insert(str[i]);
  39. }
  40. for(it = st.begin(); it != st.end(); ++it) {
  41. tmp = *it;
  42. int len = tmp.length();
  43. for(int i = 0; i < len; ++i) {
  44. if(tmp[i] == '#') {
  45. ++cnt[i];
  46. }
  47. }
  48. }
  49. bool flag = true;
  50. for(int i = 0; i < m; ++i) {
  51. if(cnt[i] > 1) {
  52. flag = false;
  53. break;
  54. }
  55. }
  56. if(flag) {
  57. cout << "Yes\n";
  58. } else {
  59. cout << "No\n";
  60. }
  61. }
  62. return 0;
  63. }

B. Three-level Laser

题意

一个原子的电子可以处在 个不同的能级 上,若某个电子的基态能级为 ,每当电子吸收 的能量后,电子将跃迁到能级 ,接着电子将跃迁到一个低于 的能级 并释放出能量为 的光子,最后回到基态 并损失 的能量,跃迁过程中必然有 。由于某些限制,电子吸收的能量不能超过 ,设能量的利用率为 ,问在所有情况下,最大的能量利用率。

输入

第一行包含两个整数 ,第二行包含 个整数

输出

如果无法找到 个合法的能级提供跃迁,则输出 ,否则输出可能的最大能量利用率 ,误差在 内均认为答案正确。

样例

输入
4 4
1 3 5 7
输出
0.5
提示
选择 分别为 ,则能量利用率为
输入
10 8
10 13 15 16 17 19 20 22 24 25
输出
0.875
提示
选择能级 ,能量利用率为
输入
3 1
2 5 10
输出
-1

题解

对于每一个能级 ,找到最大的能跃迁到的能级 ,并选择 ,这样就能得到最大的能量利用率,如果所有的 之间不存在可以跃迁的能级,则输出

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 100000 + 100;
  21. int n, U;
  22. int num[maxn];
  23. int *it;
  24. double ans;
  25. int main() {
  26. #ifdef LOCAL
  27. freopen("test.txt", "r", stdin);
  28. // freopen("test1.out", "w", stdout);
  29. #endif // LOCAL
  30. ios::sync_with_stdio(false);
  31. while(scanf("%d%d", &n, &U) != EOF) {
  32. ans = 0;
  33. for(int i = 0; i < n; ++i) {
  34. scanf("%d", &num[i]);
  35. }
  36. bool flag = false;
  37. for(int i = 0; i < n; ++i) {
  38. it = upper_bound(num, num + n, num[i] + U);
  39. if(it - (num + i) >= 3) {
  40. flag = true;
  41. --it;
  42. ans = max(ans, (double)(*it - num[i + 1]) / (*it - num[i]));
  43. }
  44. }
  45. if(flag) {
  46. printf("%.10f\n", ans);
  47. } else {
  48. printf("-1\n");
  49. }
  50. }
  51. return 0;
  52. }

C. Riverside Curio

题意

打算观察一条河的水位 天,每天他都在水平面处做一个标记,水的涨落不会将之前的标记冲走,每天他都会记录下严格在水平面上方的标记数量 ,如果记严格在水平面下方的标记数为 ,求 的最小值。

输入

第一行为一个整数 ,第二行为 个整数

输出

输出最小的 的值。

样例

输入
6
0 1 0 3 0 2
输出
6
提示
最优的水平面的涨落情况如下:



注意第 天必须要打上 个新的标记,否则无法保证第 天在水平面上方出现 个标记。
输入
5
0 1 2 1 2
输出
1
提示
最优的水平面的涨落情况如下:

输入
5
0 1 1 2 2
输出
0

题解

首先找到最大的 ,在这一天之后不再生成新的标记,这样可以使得在这一天之后的 的值最小,这一天之后的 的和为 ,在这一天之前,只要计算出每一天最少的标记数即可,我们从第 天往前枚举 ,设总的标记数为 ,如果在第 天之前的最大值小于 ,那么第 天的标记就可以认为是新画上的,将 减一,继续往前枚举,每天在水平面下方的标记数为

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 100000 + 100;
  21. int n, tot;
  22. LL ans;
  23. int num[maxn], Max[maxn];
  24. int main() {
  25. #ifdef LOCAL
  26. freopen("test.txt", "r", stdin);
  27. // freopen("test1.out", "w", stdout);
  28. #endif // LOCAL
  29. ios::sync_with_stdio(false);
  30. while(scanf("%d", &n) != EOF) {
  31. ans = 0;
  32. tot = 0;
  33. int Index = 1;
  34. for(int i = 1; i <= n; ++i) {
  35. scanf("%d", &num[i]);
  36. if(num[i] > num[Index]) {
  37. Index = i;
  38. }
  39. }
  40. tot = num[Index];
  41. Max[0] = 0;
  42. for(int i = 1; i <= n; ++i) {
  43. Max[i] = max(Max[i - 1], num[i]);
  44. }
  45. for(int i = Index + 1; i <= n; ++i) {
  46. ans += num[Index] - num[i];
  47. }
  48. for(int i = Index; i >= 1; --i) {
  49. ans += tot - num[i];
  50. if(Max[i - 1] < tot) {
  51. --tot;
  52. }
  53. }
  54. printf("%I64d\n", ans);
  55. }
  56. return 0;
  57. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注