Codeforces Round #472 (based on VK Cup 2018 Round 2)解题报告

A. Mystical Mosaic

题目大意:

  给一个空白矩阵,每次可以选一些行和一些列并让他们的交点涂黑,每次选的行和列不能有交集。

  给出最后的矩阵样子,问能不能经过若干次以上操作后得到最后的矩阵。

思路:

  每一行都可以确定哪些列必须被覆盖记为Si,任意两个不同的行之间要么S相等要么相交为空集。

  所以我们要做的就是确定任意两行,他们的S要么相等要么相交为空集,这是答案为Yes的充要条件。

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 char table[55][55];
 5
 6 int main() {
 7     int n, m;
 8     cin >> n >> m;
 9     for (int i = 0; i < n; i++) cin >> table[i];
10     bitset<55> col[55]; // 用bitset表示S
11     for (int i = 0; i < n; i++) {
12         for (int j = 0; j < m; j++) {
13             col[i][j] = table[i][j]==‘#‘?1:0;
14         }
15     }
16     bool flag = true;
17     for (int i = 0; i < n; i++) {
18         for (int j = i + 1; j < n; j++) {
19             for (int k = 0; k < m; k++) {
20                 if (!(col[i]==col[j] || (col[i]&col[j]).count()==0))
21                 {flag=false; break;}
22             }
23         }
24     }
25     if (flag) cout << "Yes" << ‘\n‘;
26     else cout << "No" << ‘\n‘;
27     return 0;
28 }

B. Three-level Laser

题目大意:

  给一个数组,从左到右依次选3个数a, b, c,让(a-b)/(a-c)最大。

思路:

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int a[maxn];
int n, u;
int main() {
    while (cin >> n >> u) {
        for (int i = 0; i < n; i++) cin >> a[i];
        int i = 0, k = i;
        double ans = -1;
        for (; i < n - 2; i++) {
            for (; k < n - 1 && a[k + 1] - a[i] <= u; k++) ;
            if (k - i >= 2) {
                ans = max(ans, 1 + 1.0 * (a[i] - a[i + 1]) / (a[k] - a[i]));
            }
        }
        printf("%.9lf\n", ans);
    }
    return 0;
}

C. Riverside Curio

题目大意:

思路:

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 100000 + 10;
 4 typedef long long LL;
 5 int a[maxn], t[maxn];
 6 int n;
 7 int main() {
 8     while (cin >> n) {
 9         for (int i = 0; i < n; i++) cin >> a[i];
10         int cur = 0;
11         for (int i = n - 1; i >= 0; i--) {
12             cur = t[i] = max(max(0, cur - 1), a[i] + 1);
13         }
14         LL ans = 0; cur = 0;
15         for (int i = 0; i < n; i++) {
16             ans += (cur = max(cur, t[i]));
17         }
18         for (int i = 0; i < n; i++) ans -= a[i] + 1;
19         cout << ans << ‘\n‘;
20     }
21     return 0;
22 }

D. Contact ATC

题目大意:

思路:

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 typedef long long LL;
 5
 6 const int maxn = 100000 + 10;
 7 // refer to model answer
 8 struct fraction {
 9     template <typename T>
10     static inline T gcd(const T a, const T b) {
11         return (b == 0) ? a : gcd(b, a % b);
12     }
13
14     LL num, deno;
15
16     inline void simplify() {
17         if (deno < 0) { num *= -1; deno *= -1; }
18         LL g = gcd(num < 0 ? -num : num, deno);
19         num /= g, deno /= g;
20     }
21
22     fraction() {}
23     fraction(LL num, LL deno):num(num), deno(deno) { simplify(); }
24
25     inline bool operator<(const fraction &rhs) const {
26         return num * rhs.deno < deno * rhs.num;
27     }
28     inline bool operator!=(const fraction &rhs) const {
29         return num * rhs.deno != deno * rhs.num;
30     }
31 };
32
33 struct BIT {
34     static const int maxn = ::maxn;
35     int f[maxn];
36     BIT() { memset(f, 0, sizeof f); }
37     inline void init() { memset(f, 0, sizeof f); }
38     inline void add(int pos, int inc) {
39         for (pos++; pos < maxn; pos += (pos & -pos))
40             f[pos] += inc;
41     }
42     inline int sum(int rg) {
43         int ans = 0;
44         for (++rg; rg; rg -= (rg & -rg)) {
45             ans += f[rg];
46         }
47         return ans;
48     }
49     inline int sum(int lf, int rg) {
50         return sum(rg) - sum(lf - 1);
51     }
52 }bit;
53
54 int n, w;
55 pair<fraction, fraction> t[maxn];
56 pair<fraction, int> d[maxn];
57 int p[maxn];
58
59 int main() {
60     while (cin >> n >> w) {
61         for (int i = 0; i < n; i++) {
62             int x, v; cin >> x >> v;
63             // cout << x << ‘ ‘ << v << ‘\n‘;
64             t[i].first = fraction(-x, v - w);
65             t[i].second = fraction(-x, v + w);
66         }
67         // 排序。如果第一个时间相等则应该按照第二个时间从大到小排序
68         for (int i = 0; i < n; i++) t[i].second.num *= -1;
69         sort(t, t + n);
70         for (int i = 0; i < n; i++) t[i].second.num *= -1;
71 //        for (int i = 0; i < n; i++) {
72 //            printf("%lld %lld\n", t[i].first.num, t[i].first.deno);
73 //        }
74         // 对速度为v+w的到达时间的离散化。第一个时间不用离散化,因为已经排序了,下标就是离散化
75         for (int i = 0; i < n; i++) {
76             d[i].first = t[i].second;
77             d[i].second = i;
78         }
79         sort(d, d + n);
80         for (int i = 0, rk = -1; i < n; i++) {
81             if (i == 0 || d[i].first != d[i - 1].first) rk++;
82             p[d[i].second] = rk;
83         }
84         // 求逆序对
85         LL ans = 0; bit.init();
86         for (int i = 0; i < n; i++) {
87             ans += bit.sum(p[i], maxn - 2);
88             // cout << bit.sum(p[i], maxn - 1) << endl;
89             bit.add(p[i], 1);
90         }
91         cout << ans << ‘\n‘;
92     }
93     return 0;
94 }

原文地址:https://www.cnblogs.com/ZengWangli/p/8729317.html

时间: 2024-08-27 15:25:02

Codeforces Round #472 (based on VK Cup 2018 Round 2)解题报告的相关文章

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 stri

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数组中连续的

codeforces cf round#505(based on vk cup 2018 final) C. Plasticine zebra

构造题,把整个串想象成一个环.每次把环断开并反转的时候从切口处看进去的顺序是和刚开始从头到尾的顺序是一样的.于是每次不管如何翻转最后都要找到这个环上最大的连续子段长度 #include<bits/stdc++.h> using namespace std; string s; int main() { cin>>s; int tmp=s.size(); s=s+s; int ans=0; int len=1; for(int i=0;i<(int)s.size()-1;i++

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching B. Pair of Toys C. Bracket Subsequence D. Array Restoration-区间查询最值(RMQ(ST))

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Pattern Matching 题意就是匹配字符的题目,打比赛的时候没有看到只有一个" * ",然后就写挫了,被hack了,被hack的点就是判一下只有一个" * ". 1 //A 2 #include<iostream> 3 #include<cstdio&g

Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)

B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mat

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

考场上只做出了ABDE C都挂了... 题解: A 题解: 模拟 判断前面一段是否相同,后面一段是否相同,长度是否够(不能有重叠) Code: 1 #include<stdio.h> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<vector> 6 #include<map> 7 #include<set> 8 #inclu

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) D. Array Restoration

D. Array Restoration time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Initially there was an array aa consisting of nn integers. Positions in it are numbered from 11 to nn. Exactly qq querie