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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- IDEA SpringBoot-Mybatis-plus 实现增删改查(CRUD)
上一篇: IDEA SpringBoot-Mybatis实现增删改查(CRUD) 下一篇:Intellij IDEA 高效使用教程 (插件,实用技巧) 最好用的idea插件大全 一.前言 Mybati ...
- 【Java分享客栈】我曾经的两个Java老师一个找不到工作了一个被迫转行了
前言 写这篇文章的初衷主要是最近发生了两件事,让我感慨良多,觉得踏入这个行业的初始,有些事情就应该长远考虑,这样对职业发展才更有利,仅仅停留在技术的追求上固然能壮大自身,可逆水行舟的程序员们终究会面临 ...
- 【机翻】RTnet – 灵活的硬实时网络框架
目录 RTnet – 灵活的硬实时网络框架 0 摘要 1 介绍 2 基础服务 2.1 数据包管理 2.2 UDP/IP 实现 2.3 Driver Layer 2.4 应用程序接口 2.5 捕获扩展 ...
- LINUX系统虚拟机环境的安装
安装VM和Centos Step 1 去BIOS里修改设置开启虚拟化设备支持 设置BIOS: 1.开机按F2.F12.DEL.ESC等进入BIOS,一般来说可以看屏幕的左下角有提示按键进入BIOS,进 ...
- 团队Arpha5
队名:观光队 组长博客 作业博客 组员实践情况 王耀鑫 **过去两天完成了哪些任务 ** 文字/口头描述 完成服务器连接数据库部分代码 展示GitHub当日代码/文档签入记录 接下来的计划 服务器网络 ...
- SpringBoot从0到0.7——序言
SpringBoot从0到0.7-- 序言 最近做java代码审计发现很多地方看不懂,所以就开始学框架,自己做网站来了解网站的运行原理.函数.接口.参数等等,通过学习SpringBoot框架来从点到面 ...
- Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=aarch64. path=/org/sqlite/native/Mac/aarch64
编译项目报错: Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=aarch ...
- 什么叫做 Docker
什么叫做 Docker 本文写于 2020 年 11 月 5 日 没有人会喜欢环境配置 在去年的时候我开始学习 Python,并利用 Python 制作了一些小工具.但问题是我很难让别人去用我的软件, ...
- Celery-Task参数方法
@celery.task(bind=True, name='name') def function_name(): pass # task方法参数 name : 可以显式指定任务的名字:默认是模块的命 ...
- 150_1秒获取Power BI Pro帐号
博客:www.jiaopengzi.com 请点击[阅读原文]获取帐号 一.背景 当你来到这篇文章的时候,我想你已经在网上搜索了一圈了.网上有一大把教你如何注册Power BI帐号的方法,我们这里就不 ...