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 ...
随机推荐
- 【RF库Collections测试】Copy Dictionary
Name: Copy DictionarySource:Collections <test library>Arguments:[ dictionary ]Returns a copy o ...
- lua常用操作
1 .Lua生成随机数: Lua 生成随机数需要用到两个函数:math.randomseed(xx), math.random([n [, m]]) 1. math.randomseed(n) 接收一 ...
- iOS事件拦截(实现触摸任意位置隐藏指定view)
项目里有一个需求,类似新浪或者腾讯微博的顶部title栏的类别选择器的消失(在选择器展开的时候,触摸屏幕任何地方使其消失). 最开始的想法是当这个选择器(selectorView)展开的时候,在当前屏 ...
- 使用类/结构体时关于ZeroMomery用法错误
今天同事在写了如下结构体: typedef struct _tagInfo { std::list<int> lst; std::vector<int> nVec; } INF ...
- ubuntu安装TexturePicker
TexturePacker网页:https://www.codeandweb.com/texturepackerTexturePacker下载页面:https://www.codeandweb.com ...
- IDEA Intellij 打开springboot项目 配置文件无法出现输入提示
需要将java代码和资源文件进行标记
- LNMP redis 安装、PHPredis扩展配置、服务器自启动、redis认证密码
背景: LNMP 环境(centos7) 一. 安装redis 1.下载,解压,编译 $ cd /usr/local$ wget http://download.redis.io/releases/r ...
- JavaWeb温习之HttpServletResquest对象
HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象提供的方法,可以获得客户端请求的所有信息. 1 ...
- elk日志分析与发掘深入分析
elk日志分析与挖掘深入分析 1 为什么要做日志采集? 2 挖财自己的日志采集和分析体系应该怎么建? 2.1 日志的采集 2.2 日志的汇总与过滤 2.3 日志的存储 2.4 日志的分析与查询 3 需 ...
- 【BZOJ3362-3365】USACO水题四连A
[BZOJ3362][Usaco2004 Feb]Navigation Nightmare 导航噩梦 Description 农夫约翰有N(2≤N≤40000)个农场,标号1到N,M(2≤M≤ ...