Codeforces Round #783 (Div. 2)
A. Direction Change
题意
从(1,1)点出发到(n,m),每次可以向上下左右四个方向移动,但是不能与上次移动方向相同
最少要移动多少不,如果不能到达输出 -1
思路

假设n<m
如图,先走到边界用 2*n 步,接下来如果离目标 1 格加1即可,如果离目标 2 格,则如下图

共需要走4步
代码
#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e3 + 5;
int n, m, a[maxm];
bool f[maxm][maxm];
int main()
{
int t;
cin >> t;
while (t--)
{
int a, b, x, y;
cin >> x >> y;
a = min(x, y), b = max(x, y);
if (a == 1 && b > 2)
{
cout << -1 << endl;
continue;
}
if (a == 1 && b == 2)
{
cout << 1 << endl;
continue;
}
int ans = 0;
ans = (a - 1) * 2;
b = b - a;
ans += (b / 2) * 4 + (b % 2);
cout << ans << endl;
} return 0;
}
B. Social Distance
题意
有 m 把椅子摆成一个环,有 n 个人每个人有一个对应的值 ,表示其左右两边各有
个椅子不能坐人
问所有人是否都可以坐下
思路
我们首先可以让 最大的先坐,为了让空椅子利用率最大,把第二大和第三大的分别坐在其左右两边,以次类推每一个人相当于只占用了一边另一边包含在
比他大的上一个人中,一直加到最小和次小,此时最小的不用加,因为其两边包含在第二小和第三小中,因为最大的两边都用上因此要加两次
特判当 n>m 直接错误
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxm = 1e3 + 5;
int main()
{
int t;
cin >> t;
while (t--)
{
int a, b;
cin >> a >> b;
int mas = 0, mis = 1e9 + 7;
int s[a];
for (int i = 0; i < a; i++)
{
cin >> s[i];
mas = max(mas, s[i]);
mis = min(mis, s[i]);
}
if (a > b)
{
cout << "NO\n";
continue;
}
ll ans = mas + a - mis;
for (int i = 0; i < a; i++)
{
ans += s[i];
if (ans > b)
break;
}
if (ans > b)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
Make it Increasing
题意
给定一个序列 a ,b 为一个全零序列,每次操作可以使得 或
求使得 b b严格单调上升的最少的操作次数
思路
首先注意到,这些操作在同一个位置交替是没有意义的。因此考虑直接枚举某个位置不改变(0),其左侧全减,右侧全加。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[5005], mis = 1e18;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int j = 1; j <= n; j++)
{
ll ans = 0, sum = 0;
for (int i = j - 1; i >= 1; i--)
{
ans += a[i] - ans % a[i];
sum += ans / a[i];
}
ans = 0;
for (int i = j + 1; i <= n; i++)
{
ans += a[i] - ans % a[i];
sum += ans / a[i];
}
mis = min(mis, sum);
}
cout << mis << "\n";
return 0;
}
Codeforces Round #783 (Div. 2)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 五分钟配置 MinGW-W64 编译工具
编译器是一个诸如 C 语言撰写的源程序一步一步走向机器世界彼岸的桥梁. Gnu 项目的 GCC 编译器是常用的编译器之一.儿在Windows 上也有 MinGW 这样可用的套件,可以让我们使用 GCC ...
- 记一次jenkins发送邮件报错 一直报错 Could not send email as a part of the post-build publishers问题
写在前面 虽然Jenkins是开源.免费的,好处很多,但有些功能上的使用,我个人还是很不喜欢,感觉用起来特别麻烦.繁琐. 为什么? 就拿这个邮件配置来说吧,因重装系统,电脑需要配置很多东西,结果今天就 ...
- 20202127 实验一《Python程序设计》实验报告
20202127 2022-2022-2 <Python程序设计>实验一报告课程:<Python程序设计>班级: 2021姓名: 马艺洲学号:20202127实验教师:王志强实 ...
- JavaCV的摄像头实战之七:推流(带声音)
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是<JavaCV的摄像头实战> ...
- Django前后端交互&数据验证
一.前端--->后端 1.form表单 <form method="post" action="/test/?a=1&b=2"> {% ...
- [AcWIng 799] 最长连续不重复子序列
点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], s[N]; int mai ...
- 开发一个不需要重写成Hive QL的大数据SQL引擎
摘要:开发一款能支持标准数据库SQL的大数据仓库引擎,让那些在Oracle上运行良好的SQL可以直接运行在Hadoop上,而不需要重写成Hive QL. 本文分享自华为云社区< ...
- 虚拟机VMware 安装centos、常规配置、共享文件等
安装centos7[通过vm来安装运行centos7] 一.准备工作 1.centos7 的安装镜像下载链接:http://isoredirect.centos.org/centos/7/isos/x ...
- NLP教程(3) | 神经网络与反向传播
作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/36 本文地址:http://www.showmeai.tech/article-det ...
- 按照 Promise/A+ 规范逐行注释并实现 Promise
0. 前言 面试官:「你写个 Promise 吧.」 我:「对不起,打扰了,再见!」 现在前端越来越卷,不会手写 Promise 都不好意思面试了(手动狗头.jpg).虽然没多少人会在业务中用自己实现 ...