A. Elevator or Stairs?

签.

 #include <bits/stdc++.h>
using namespace std; int x, y, z, t[]; int main()
{
while (scanf("%d%d%d", &x, &y, &z) != EOF)
{
for (int i = ; i < ; ++i) scanf("%d", t + i);
int a = (abs(z - x) + abs(x - y)) * t[] + * t[];
int b = abs(x - y) * t[];
puts(a <= b ? "YES" : "NO");
}
return ;
}

B. Appending Mex

签.

 #include <bits/stdc++.h>
using namespace std; #define N 100010
int n, a[N], vis[N], last; void solve()
{
for (int i = ; i <= n; ++i)
{
while (vis[last + ]) ++last;
if (a[i] > last + )
{
printf("%d\n", i);
return;
}
vis[a[i]] = ;
}
puts("-1");
} int main()
{
while (scanf("%d", &n) != EOF)
{
memset(vis, , sizeof vis); last = -;
for (int i = ; i <= n; ++i) scanf("%d", a + i);
solve();
}
return ;
}

C. Candies Distribution

Upsolved.

题意:

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

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

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

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

思路:

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

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

$再检查一遍即可$

 #include <bits/stdc++.h>
using namespace std; #define N 1010
int n, l[N], r[N], v[N]; int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", l + i);
for (int i = ; i <= n; ++i) scanf("%d", r + i);
for (int i = ; i <= n; ++i) v[i] = n - l[i] - r[i];
bool flag = true;
for (int i = ; i <= n; ++i)
{
for (int j = ; j < i; ++j)
if (v[j] > v[i])
--l[i];
for (int j = i + ; j <= n; ++j)
if (v[j] > v[i])
--r[i];
if (l[i] != || r[i] != )
{
flag = false;
break;
}
}
if (!flag) puts("NO");
else
{
puts("YES");
for (int i = ; i <= n; ++i)
printf("%d%c", v[i], " \n"[i == n]);
}
}
return ;
}

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$

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

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

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

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

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 200010
int n, k;
int a[N];
map <int, int> mp; int main()
{
while (scanf("%d%d", &n, &k) != EOF)
{
mp.clear(); mp[] = ;
int d = ( << k) - ;
for (int i = ; i <= n; ++i) scanf("%d", a + i);
for (int i = ; i <= n; ++i)
{
a[i] ^= a[i - ];
++mp[a[i]];
if (mp.find(a[i] ^ d) == mp.end()) mp[a[i] ^ d] = ;
}
ll res = ;
for (auto it : mp) if (it.first > (it.first ^ d))
{
int a = it.second, n = a + mp[it.first ^ d];
int b = n / ;
res += (1ll * n * n + 2ll * b * b - 2ll * b * n - n) / ;
}
printf("%lld\n", 1ll * n * (n + ) / - res);
}
return ;
}

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

  1. Mail.Ru Cup 2018 Round 3 B. Divide Candies

    题目链接 分析一下题意可以得到题目要求的是满足下面这个 公式的不同的i,ji,ji,j的方案数; 即(i2+j2)mod&ThinSpace;&ThinSpace; m=0 (n ≤  ...

  2. Mail.Ru Cup 2018 Round 3

    A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  3. Mail.Ru Cup 2018 Round 2

    A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

  4. [codeforces Mail.Ru Cup 2018 Round 3][B Divide Candies ][思维+数学]

    https://codeforces.com/contest/1056/problem/B 题意:输入n,m    求((a*a)+(b*b))%m==0的(a,b)种数(1<=a,b<= ...

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

    http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题 ...

  6. Mail.Ru Cup 2018 Round 2 Solution

    A. Metro Solved. 题意: 有两条铁轨,都是单向的,一条是从左往右,一条是从右往左,Bob要从第一条轨道的第一个位置出发,Alice的位置处于第s个位置,有火车会行驶在铁轨上,一共有n个 ...

  7. Mail.Ru Cup 2018 Round 3 Solution

    A. Determine Line Water. #include <bits/stdc++.h> using namespace std; ]; int main() { while ( ...

  8. Mail.Ru Cup 2018 Round 1 virtual participate记

    因为睡过了只好vp. A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include< ...

  9. Mail.Ru Cup 2018 Round 2C(__gcd)

    #include<bits/stdc++.h>using namespace std;long long mx(long long l1,long long r1,long long l2 ...

随机推荐

  1. nodejs搭建简单web服务器!!

    var http = require("http"), url = require("url"), path = require("path" ...

  2. ActiveMQ伪集群部署

    本文借鉴http://www.cnblogs.com/guozhen/p/5984915.html,在此基础上进行了完善,使之成为一个完整版的伪分布式部署说明,在此记录一下! 一.本文目的 介绍如何在 ...

  3. windbg载入目标模块pdb

    .reload /f xxxx.dll ld xxxx 以kdcom为例子 .reload /f kdcom.dll ld kdcom 二选一

  4. PropertyPlaceholderConfigurer读取配置文件

    1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是 BeanFactoryPostProcessor接口的一个实现.PropertyPlaceho ...

  5. 在linux下安装Avria(小红伞)

    1.下载AntiVir PersonalEdition Classic for linux http://www.free-av.com/ 2.解压: tar zxvf antivir.tar.gz ...

  6. SMGP3.0协议的概念知识

    该项目主页在https://code.google.com/archive/p/smgp/,可以使用VPN进去看看,该项目是开源的,根据SMGP3.0协议写的API,我们要用的话直接调用就好了,这里主 ...

  7. 微信小程序 --- 登录页面

    思路:在个人中心页面,首先判断全局的 app.js 里面的 globalData 里面的 is_login 状态,并且判断 缓存数据中的 is_login 状态,如果都为真,就正常显示,如果有一个为假 ...

  8. KM算法(最优匹配)

    hdu2255 奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. Css-常用css

    /*怪异盒子模型*/ .box { box-sizing: border-box; } /*水平居中的内联块级*/ .inBlock { display: inline-block; vertical ...

  10. Service学习笔记

    一 什么是Service Service作为安卓四大组件之一,拥有重要的地位.Service和Activity级别相同,只是没有界面,是运行于后台的服务.这个运行“后台”是指不可见,不是指在后台线程中 ...