Mail.Ru Cup 2018 Round 1

A. Elevator or Stairs?

签.

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

B. Appending Mex

签.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 #define N 100010
 5 int n, a[N], vis[N], last;
 6
 7 void solve()
 8 {
 9     for (int i = 1; i <= n; ++i)
10     {
11         while (vis[last + 1]) ++last;
12         if (a[i] > last + 1)
13         {
14             printf("%d\n", i);
15             return;
16         }
17         vis[a[i]] = 1;
18     }
19     puts("-1");
20 }
21
22 int main()
23 {
24     while (scanf("%d", &n) != EOF)
25     {
26         memset(vis, 0, sizeof vis); last = -1;
27         for (int i = 1; i <= n; ++i) scanf("%d", a + i);
28         solve();
29     }
30     return 0;
31 }

C. Candies Distribution

Upsolved.

题意:

一个序列,$a_i取值为[1, n]$

告诉你$每个数左边有多少数大于你,记为l_i$

$右边有多少数大于你,记为r_i$

让你还原出这个序列,如果没有合法的输出$NO$

思路:

$我们知道一个数的l_i + r_i 越大,那么这个数越小$

$那我们不妨令 a_i = n - l_i - r_i$

$再检查一遍即可$

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 #define N 1010
 5 int n, l[N], r[N], v[N];
 6
 7 int main()
 8 {
 9     while (scanf("%d", &n) != EOF)
10     {
11         for (int i = 1; i <= n; ++i) scanf("%d", l + i);
12         for (int i = 1; i <= n; ++i) scanf("%d", r + i);
13         for (int i = 1; i <= n; ++i) v[i] = n - l[i] - r[i];
14         bool flag = true;
15         for (int i = 1; i <= n; ++i)
16         {
17             for (int j = 1; j < i; ++j)
18                 if (v[j] > v[i])
19                     --l[i];
20             for (int j = i + 1; j <= n; ++j)
21                 if (v[j] > v[i])
22                     --r[i];
23             if (l[i] != 0 || r[i] != 0)
24             {
25                 flag = false;
26                 break;
27             }
28         }
29         if (!flag) puts("NO");
30         else
31         {
32             puts("YES");
33             for (int i = 1; i <= n; ++i)
34                 printf("%d%c", v[i], " \n"[i == n]);
35         }
36     }
37     return 0;
38 }

D. Changing Array

Upsolved.

题意:

给一个序列,$可以将每个位置上的数取反$

$求最多有多少子区间的异或和不为0$

思路:

求最多有多少子区间$异或和不为0,比较困难$

$正难则反,我们考虑反面,我们求最少有多少个子区间异或和为0$

$我们知道一段区间l, r的异或和是S_r \oplus S_[l - 1]$

$S表示前缀异或$

$那么一个序列的前缀异或里面如果有x个a, 那么子区间异或为0的个数为\frac{a \cdot (a - 1)}{2}$

$我们考虑 b = ~a, 而且a, b之间可以互相转化,并且只能互相转化,而不能转化为其他的数字$

$令x = a的个数, y = b的个数$

$我们令n = x + y $

$那么a, b构成的子区间个数就是 \frac{x \cdot (x - 1)}{2} + \frac{y \cdot (y - 1)}{2}$

$将n = x + y 代入$

$就得到一个一元二次方程,取对称轴即可$

$我们考虑转化都是\oplus (1 << k) - 1$

转化两次即相当于没有转化

$所以每个前缀异或都能转化为自己想要的那个数$

$为什么不考虑前面的数转化了会影响到后面的前缀异或?$

$那后面那个如果受影响了,再转化回来不就好了?$

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 #define ll long long
 5 #define N 200010
 6 int n, k;
 7 int a[N];
 8 map <int, int> mp;
 9
10 int main()
11 {
12     while (scanf("%d%d", &n, &k) != EOF)
13     {
14         mp.clear(); mp[0] = 1;
15         int d = (1 << k) - 1;
16         for (int i = 1; i <= n; ++i) scanf("%d", a + i);
17         for (int i = 1; i <= n; ++i)
18         {
19             a[i] ^= a[i - 1];
20             ++mp[a[i]];
21             if (mp.find(a[i] ^ d) == mp.end()) mp[a[i] ^ d] = 0;
22         }
23         ll res = 0;
24         for (auto it : mp) if (it.first > (it.first ^ d))
25         {
26             int a = it.second, n = a + mp[it.first ^ d];
27             int b = n / 2;
28             res += (1ll * n * n + 2ll * b * b - 2ll * b * n - n) / 2;
29         }
30         printf("%lld\n", 1ll * n * (n + 1) / 2 - res);
31     }
32     return 0;
33 }

原文地址:https://www.cnblogs.com/Dup4/p/10354410.html

时间: 2024-08-03 08:26:22

Mail.Ru Cup 2018 Round 1的相关文章

[题解]Mail.Ru Cup 2018 Round 1 - A. Elevator or Stairs?

[题目] A. Elevator or Stairs? [描述] Masha要从第x层楼去第y层楼找Egor,可以选择爬楼梯或者坐直升电梯.已知爬楼梯每层需要时间t1:坐直升电梯每层需要时间t2,直升电梯开门或者关门一次需要时间t3,当前直升电梯在第z层楼,直升电梯门是在关闭状态的.如果爬楼梯总时间严格小于坐直升电梯,则选择爬楼梯并输出YES,否则选择坐直升电梯并输出NO. 数据范围:1<=x,y,z,t1,t2,t3<=1000 [思路] 爬楼梯总时长:t1*abs(x-y) 坐直升电梯总时

[codeforces Mail.Ru Cup 2018 Round 1 D][ xor 操作]

http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题目分析:首先易知每个位置的前缀异或和的值只有两种,因为对元素进行取反时,取偶数个元素异或和不变,奇数个元素就是原值取反.然后由于对一个位置取反,不会影响后面位置与这个位置的前缀异或和相同的位置个数(因为这个位置取反后,后面各个位置的前缀异或和也跟着改变),所以一个位置的改变只会影响与前面位置前缀和相

Mail.Ru Cup 2018 Round 3 Solution

A. Determine Line Water. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n, vis[110]; 5 6 int main() 7 { 8 while (scanf("%d", &n) != EOF) 9 { 10 memset(vis, 0, sizeof vis); 11 for (int i = 1, tot, x; i <= n; ++i) 12 { 13 s

Mail.Ru Cup 2018 Round 2 B. Alice and Hairdresser

传送门 待调bug https://paste.ubuntu.com/p/ZMzGkWMjkj/ 原文地址:https://www.cnblogs.com/violet-acmer/p/10916367.html

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 #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 #472 (based on VK Cup 2018 Round 2)解题报告

A. Mystical Mosaic 题目大意: 给一个空白矩阵,每次可以选一些行和一些列并让他们的交点涂黑,每次选的行和列不能有交集. 给出最后的矩阵样子,问能不能经过若干次以上操作后得到最后的矩阵. 思路: 每一行都可以确定哪些列必须被覆盖记为Si,任意两个不同的行之间要么S相等要么相交为空集. 所以我们要做的就是确定任意两行,他们的S要么相等要么相交为空集,这是答案为Yes的充要条件. 代码: 1 #include <bits/stdc++.h> 2 using namespace st

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