Yahoo Programming Contest 2019
A - Anti-Adjacency
签.
#include <bits/stdc++.h>
using namespace std; int main()
{
int n, k;
while (scanf("%d%d", &n, &k) != EOF)
{
int remind = (n + ) / ;
puts(k <= remind ? "YES" : "NO");
}
return ;
}
B - Path
签.
#include <bits/stdc++.h>
using namespace std; int x, y, Max;
vector <int> G[]; void DFS(int u, int fa, int deep)
{
Max = max(Max, deep);
for (auto v : G[u]) if (v != fa)
DFS(v, u, deep + );
} int main()
{
while (scanf("%d%d", &x, &y) != EOF)
{
for (int i = ; i <= ; ++i) G[i].clear();
G[x].push_back(y);
G[y].push_back(x);
for (int i = ; i <= ; ++i)
{
scanf("%d%d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
Max = ;
DFS(, , );
puts(Max == ? "YES" : "NO");
}
return ;
}
C - When I hit my pocket...
签.
#include <bits/stdc++.h>
using namespace std; #define ll long long
int k, a, b; int main()
{
while (scanf("%d%d%d", &k, &a, &b) != EOF)
{
if (a >= (b - ) || k < a) printf("%d\n", k + );
else
{
k -= a - ;
int Loop = k / ;
if (Loop == ) printf("%d\n", a + k % );
else printf("%lld\n", 1ll * b + 1ll * (Loop - ) * (b - a) + k % );
}
}
return ;
}
D - Ears
Upsolved.
题意:
有一个人在一维线段上走
$每次经过i - 0.5 i 是整数, 就在第i个位置放一颗石头$
$并且起点和终点必须是整数点,只能在整数点向$
$这样一条合法的路径可以用一个石头序列来表示$
$现在给出每个位置的石头数量,这个可能是不合法的$
$但是可以在某个位置放置或者移除一块石头$
$求最少的操作次数使得石头序列合法$
思路:
我们考虑一个合法的石头序列肯定是
零碎 + 偶数 + 奇数 + 偶数 + 零碎
这样五部分构成,并且至少有一部分的个数不为$0$
我们考虑$dp[i][j] 表示第i个位置,当前点位于第j个状态$
$转移即可$
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 200010
int n, a[N];
ll f[N][]; int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", a + i);
memset(f, 0x3f, sizeof f);
for (int i = ; i < ; ++i) f[][i] = ;
// 0 左边零碎
// 1 左边偶数
// 2 奇数
// 3 右边偶数
// 4 右边零碎
for (int i = ; i <= n; ++i)
{
ll Min = (ll)1e18, cost;
cost = a[i];
Min = min(Min, f[i - ][]);
f[i][] = Min + cost; cost = a[i] == ? : (a[i] % );
Min = min(Min, f[i - ][]);
f[i][] = Min + cost; cost = a[i] == ? : (a[i] % == );
Min = min(Min, f[i - ][]);
f[i][] = Min + cost; cost = a[i] == ? : (a[i] % );
Min = min(Min, f[i - ][]);
f[i][] = Min + cost; cost = a[i];
Min = min(Min, f[i - ][]);
f[i][] = Min + cost;
}
ll res = (ll)1e18;
for (int i = ; i < ; ++i)
res = min(res, f[n][i]);
printf("%lld\n", res);
}
return ;
}
F - Pass
Upsolved.
题意:
$有n个人,每个人手中有两个球,球有红蓝两种$
$0代表手中有两个红球$
$1代表手中有一红一蓝$
$2代表手中有两个蓝球$
$每次每个编号为非1的人,如果手中还有球,那就挑一个球给前面的人$
$编号为1的人,如果手中有球,就将球接到结果集中$
$最后结果集为一个长度为2 \cdot n的字符串,r 代表红球, b代表蓝球$
$求结果集的方案数$
思路:
$dp[i][j] 表示到第i位,已经安排了j个红球的方案数$
$那只需要考虑i + 1这一位能不能放红球后者能不能放蓝球,就能确定转移$
$我们考虑第i个人的球至少要放在第i位或者之后$
$因为传递需要一个过程$
$用前缀和维护一下,就可以知道前i位最多放多少红球, 转移即可$
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 4010
const ll MOD = (ll);
int n;
char s[N];
ll f[N][N];
int a[N], b[N]; template <class T>
void add(T &x, T &y) { x += y; if (x >= MOD) x -= MOD; } int main()
{
while (scanf("%s", s + ) != EOF)
{
n = strlen(s + );
for (int i = ; i <= n; ++i) a[i] = a[i - ] + - (s[i] - ''), b[i] = b[i - ] + s[i] - '';
memset(f, , sizeof f);
f[][] = ;
for (int i = ; i <= * n; ++i)
for (int j = ; j <= i; ++j) if (f[i][j])
{
if (a[min(i + , n)] > j) add(f[i + ][j + ], f[i][j]);
if (b[min(i + , n)] > i - j) add(f[i + ][j], f[i][j]);
}
printf("%lld\n", f[ * n][a[n]]);
}
return ;
}
Yahoo Programming Contest 2019的更多相关文章
- [AtCoder] Yahoo Programming Contest 2019
[AtCoder] Yahoo Programming Contest 2019 很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...
- Yahoo Programming Contest 2019 自闭记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- Yahoo Programming Contest 2019 补题记录(DEF)
D - Ears 题目链接:D - Ears 大意:你在一个\(0-L\)的数轴上行走,从整数格出发,在整数格结束,可以在整数格转弯.每当你经过坐标为\(i-0.5\)的位置时(\(i\)是整数),在 ...
- Yahoo Programming Contest 2019.E.Odd Subrectangles(思路 线性基)
题目链接 \(Description\) 给定一个\(n\times m\)的\(01\)矩阵.求任意选出\(r\)行.\(c\)列(共\(2^{n+m}\)种方案),使得这\(r\)行\(c\)列的 ...
- Yahoo Programming Contest 2019.F.Pass(DP)
题目链接 惊了这是什么F题...怎么我都能做出来...以后atcoder的比赛也不能走神了万一有个这样的F呢(CF已有多次了= =) \(f[i][j]\)表示Takahashi现在一共有\(i\)个 ...
- Yahoo Programming Contest 2019.D.Ears(DP)
题目链接 菜爆了啊QAQ 记起点为\(S\),终点为\(T\),走过的最靠左的点是\(L\),最靠右的点是\(R\). 那么坐标轴被分成了五段: \(0\sim L-1\):经过\(0\)次: \(L ...
- Yahoo Programming Contest 2019 E - Odd Subrectangles
E - Odd Subrectangles 思路: 对于行方案固定的情况下,假设和为奇数的列为a个,和为偶数的列为b个,a+b = m 那么从奇数里面选奇数个,即C(a, 1) + C(a, 3) + ...
- Yahoo Programming Contest 2019 F - Pass
F - Pass 思路: dp[i][j] 表示到第 i 个球为止放了 j 个蓝球的方案数 第 i 个球来自的位置的最右边是min(i, n) 转移方程看代码 代码: #pragma GCC opti ...
- Yahoo Programming Contest 2019 D - Ears
D - Ears 思路: s:起点 t:终点 l:左端点 r:右端点 以上称为关键点 dp[i][j]表示到位置 i 为止,已经经过前 j ...
- 【AtCoder】Yahoo Programming Contest 2019
A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...
随机推荐
- shell基础篇(三)--引号
---今天篇幅比较少:只介绍引号. shell中的引号有三种:双引号",单引号',反引号`1. 双引号:由双引号括起来的字符,除$.倒引号(`)和反斜线(\)仍保留其特殊功能外,其余字符均作 ...
- RecyclerView的通用适配器,和滚动时不加载图片的封装
对于RecyclerView我们需要使用RecyclerAdapter,使用方式与ListViewAdapter类似,具体代码大家可以在网上搜索,这里就只教大家使用封装后的简洁RecyclerAdap ...
- windows命令之PING DIR DEL CD TASKLIST (转)
最简单的莫过于PING命令了. PING命令的功能就是给对方主机发送IP数据包. 一般都是测试主机是否在线. 用法如下: PING 192.168.1.1.PING命令默认发送的是四个数据包,当然也可 ...
- BNU4204:动物PK
稀奇稀奇真稀奇,动物园摆出了擂台赛.小动物们纷纷上台比试,谁能获得最后的冠军呢? 动物园长发现小动物们打擂只与自身的三项属性有关:血量,攻击力和防御力.此外,小动物在赛前都为自己准备了一系列的攻击计划 ...
- LeetCode——Integer to Roman
Description: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the r ...
- [SQL]批量 更改字符集脚本,批量查询约束,批量查询索引
How to change collation of all database objects in SQL Server. Have you encountered a problem where ...
- 【php】---mysql---基本操作及使用---【巷子】
1.数据库简介 (1).什么是数据库? 一个文件 一个文件夹 一个u盘 一个硬盘......都叫做数据库 存放数据的仓库 (2).常见的数据库? mySql sql ...
- Yii 后台防止表单提交
第一种方法: 在AR类中设置rules()方法里面设置该属性为unique属性 Class Item extends \yii\db\ActiveRecord{ public function rul ...
- Create an Index
db.collection.createIndex( { name: -1 } ) Indexes — MongoDB Manual https://docs.mongodb.com/manual/i ...
- 提醒事项 1. 冥想TX 2.下班路上听歌激励自己 3. 不戴眼镜 4. 困难任务拆解
1. 冥想TX 2.下班路上听歌激励自己 3. 不戴眼镜 4. 困难任务拆解