Mail.Ru Cup 2018 Round 3 Solution
A. Determine Line
Water.
#include <bits/stdc++.h>
using namespace std; int n, vis[]; int main()
{
while (scanf("%d", &n) != EOF)
{
memset(vis, , sizeof vis);
for (int i = , tot, x; i <= n; ++i)
{
scanf("%d", &tot);
while (tot--)
{
scanf("%d", &x);
++vis[x];
}
}
for (int i = ; i <= ; ++i) if (vis[i] == n) printf("%d ", i);
puts("");
}
return ;
}
B. Divide Candies
Solved.
题意:
有$n \cdot n 的网格,每个网格放的糖数是(i^2 + j^2), i, j 表示行列$
求有多少个格子上的糖数是$m的倍数$
思路:
因为$m很小,处理出m的每个余数所对应的数字个数,再加加乘乘就好了$
#include <bits/stdc++.h>
using namespace std; #define ll long long
int n, m;
ll cnt[]; ll calc(ll x, ll y)
{
if (x % m >= y) return x / m + ;
return x / m;
} int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
memset(cnt, , sizeof cnt);
for (int i = ; i < m; ++i)
cnt[i * i % m] += calc(n, i);
--cnt[]; cnt[m] = cnt[];
ll res = ;
for (int i = ; i < m; ++i) res += cnt[i] * cnt[m - i];
printf("%lld\n", res);
}
return ;
}
C. Pick Heroes
Solved.
题意:
有两支队伍,每支队伍$n个人,每个人要选一个英雄,一共有2 \cdot n 个英雄$
$两支队伍的人轮流选,但是有些英雄有对应关系,也就是说如果某一轮一个人选了其中一个$
$那么在下一轮他的对手将被强制选择另一个,每个英雄最多存在于一个对应关系中$
这里是交互题。
思路:
贪心选即可,注意自己先手的时候,尽量先贪心选有对应关系的大的那只,再从大往小取
后手的时候注意特判,自己可不可以选有对应关系的英雄,如果可以,那么就回到先手状态
#include <bits/stdc++.h>
using namespace std; #define N 2010
#define pii pair <int, int>
int n, m, t;
vector <pii> v, p;
map <int, int> mp;
int vis[N]; int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
v.clear(); mp.clear(); p.clear();
memset(vis, , sizeof vis);
for (int i = , x; i <= * n; ++i)
{
scanf("%d", &x);
p.emplace_back(x, i);
}
for (int i = , x, y; i <= m; ++i)
{
scanf("%d%d", &x, &y);
mp[x] = y;
mp[y] = x;
v.emplace_back(x, y);
}
scanf("%d", &t);
for (auto &it : v) if (p[it.first - ].first < p[it.second - ].first) swap(it.first, it.second);
sort(p.begin(), p.end(), [](pii a, pii b) { return a.first > b.first; });
if (t == )
{
int x;
for (auto &it : v)
{
printf("%d\n", it.first);
fflush(stdout);
scanf("%d", &x);
vis[it.first] = ;
vis[x] = ;
}
for (int i = v.size() + , r = ; i <= n; ++i)
{
while (vis[p[r].second]) ++r;
printf("%d\n", p[r].second);
fflush(stdout);
scanf("%d", &x);
vis[p[r].second] = ;
vis[x] = ;
}
}
else
{
int x;
for (int i = , r1 = , r2 = ; i <= n; ++i)
{
scanf("%d", &x);
vis[x] = ;
if (mp.find(x) != mp.end() && vis[mp[x]] == )
{
printf("%d\n", mp[x]);
vis[mp[x]] = ;
}
else
{
while (r1 < v.size() && vis[v[r1].first]) ++r1;
if (r1 < v.size())
{
printf("%d\n", v[r1].first);
vis[v[r1].first] = ;
}
else
{
while (vis[p[r2].second]) ++r2;
printf("%d\n", p[r2].second);
vis[p[r2].second] = ;
}
}
fflush(stdout);
}
} }
return ;
}
D. Decorate Apple Tree
Solved.
题意:
有一棵树,每个叶子要有一个颜色。
一个点被定义为好点,是在它的子树中每个叶子的颜色都不同。
求好点个数为$k的时候 k \in [1, n] 所需要的最小的颜色个数$
思路:
先处理出每个点的子树中有多少个叶子,再按从小到大排序,依次输出即可。
#include <bits/stdc++.h>
using namespace std; #define N 100010
int n;
vector <int> G[N]; int sze[N];
void DFS(int u)
{
sze[u] = ;
for (auto v : G[u])
{
DFS(v);
sze[u] += sze[v];
}
if (!sze[u]) sze[u] = ;
} int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) G[i].clear();
for (int u = , v; u <= n; ++u)
{
scanf("%d", &v);
G[v].push_back(u);
} DFS();
sort(sze + , sze + + n);
for (int i = ; i <= n; ++i) printf("%d%c", sze[i], " \n"[i == n]);
}
return ;
}
E. Check Transcription
Unsolved.
题意:
给出一个01串,以及一个字符串,求找出两个小串$A, B$
$使得01串为0的位置填A, 为1的位置填B,最后组成的串为给出的字符串$
求存在多少个$pairs(A, B)$
F. Write The Contest
Unsolved.
G. Take Metro
Unsolved.
H. Detect Robots
Unsolved.
Mail.Ru Cup 2018 Round 3 Solution的更多相关文章
- Mail.Ru Cup 2018 Round 2 Solution
A. Metro Solved. 题意: 有两条铁轨,都是单向的,一条是从左往右,一条是从右往左,Bob要从第一条轨道的第一个位置出发,Alice的位置处于第s个位置,有火车会行驶在铁轨上,一共有n个 ...
- Mail.Ru Cup 2018 Round 3 B. Divide Candies
题目链接 分析一下题意可以得到题目要求的是满足下面这个 公式的不同的i,ji,ji,j的方案数; 即(i2+j2)mod   m=0 (n ≤ ...
- Mail.Ru Cup 2018 Round 3
A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- Mail.Ru Cup 2018 Round 2
A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- [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<= ...
- [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 1
A. Elevator or Stairs? 签. #include <bits/stdc++.h> using namespace std; ]; int main() { while ...
- Mail.Ru Cup 2018 Round 1 virtual participate记
因为睡过了只好vp. A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include< ...
- 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 ...
随机推荐
- Windows7 64bits下安装TensorFlow CPU版本(图文详解)
不多说,直接上干货! Installing TensorFlow on Windows的官网 https://www.tensorflow.org/install/install_windows 首先 ...
- jdk版本不一致问题
Exception in thread "main" java.lang.UnsupportedClassVersionError: cn/com/TestApp : Unsupp ...
- 【RF库Collections测试】Get Dictionary Keys
Name:Get Dictionary KeysSource:Collections <test library>Arguments:[ dictionary ]Returns `keys ...
- Linux mii-tool 命令
mii-tool 用来查看或设置网卡的相关参数,该命令已经过时了,推荐使用 ethtool 命令 [root@localhost ~]$ mii-tool -v eth1 # 查看网卡的相关信息,包括 ...
- beginUpdates和endUpdates-实现UITableView的动画块
我们在做UITableView的修改,删除,选择时,需要对UITableView进行一系列的动作操作. 这样,我们就会用到 [tableView beginUpdates]; if (newCount ...
- cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试
#include <string> #include <tchar.h> // _TCHAR #include <stdlib.h> #include <io ...
- 【linux系列】linux防火墙的关闭开启
即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...
- CSS-自定义高度的元素背景图如何自适应以及after伪元素在ie下的处理
我都好久没更新了! 遇到一个效果,之前没有考虑清楚,设置了固定高度,到了后边,产品要加长,我就觉得设计得从新弄张长点的背景图!这不多余么? 其实分析原图还是可以再切分,再细化到不用改设计图,让我们前端 ...
- change事件的兼容性问题
当input的value被修改时,在没有失去焦点的情况下,无法触发change事件,但是可以触发propertychange事件. 但是propertychange事件存在兼容性问题: IE9以下支持 ...
- linux下有趣的几个命令
1.时常我们将频繁使用的‘ls’命令打成‘sl’,那就使用一下sl这个命令吧.在我们敲错的时候,肯定会会心一笑. 安装: yum install sl -y 或 apt-get install sl ...