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)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. golang内存对齐分析(转载)

    问题 type Part1 struct { a bool b int32 c int8 d int64 e byte } 在开始之前,希望你计算一下 Part1 共占用的大小是多少呢? func m ...

  2. python的一些练习题

    1.目前工作上有一堆的ip地址,ip是ok的,但是需要找出来不在这里面的其他ip import os a = list() with open('ip.txt','r') as f: #print(f ...

  3. 【原创】浅谈指针(十二)关于static(上)

    0.前言 这个系列基本上是一月一更到两月一更 今天写一篇关于static的,内含大量干货,做好准备 1.基础知识的回顾 1.1.内存的种类 一般来说,我们之前已经讲过的变量(或者说是内存)可以大体分为 ...

  4. 安装与基本配置DHCP服务器

    一,安装DHCP服务器角色 1,打开[开始]→[管理工具]→[服务器管理器]→"仪表板"选项的[添加角色和功能],持续单机[下一步]按钮, 直至出现下图所示的"选择服务器 ...

  5. lab_0 清华大学ucore实验环境配置详细步骤!(小白入)

    实验步骤 1.下载项目 从github上 的https://github.com/kiukotsu/ucore下载 ucore lab实验: git clone https://github.com/ ...

  6. DevOps、CI、CD都是什么鬼?

    关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ DevOps DevOps是Development和Operations的组合,是一种方法论, ...

  7. Docker的三种网络代理配置

    开源Linux 长按二维码加关注~ 上一篇:IPv6技术白皮书(附PDF下载) 有时因为网络原因,比如公司NAT,或其它啥的,需要使用代理.Docker的代理配置,略显复杂,因为有三种场景.但基本原理 ...

  8. CSS常用技术

    1.处理图片底部 5px 间距 <style> body {background: #2d97db;} .imgBox { background: #fff; font-size: 0; ...

  9. [源码解析] TensorFlow 分布式之 ParameterServerStrategy V1

    [源码解析] TensorFlow 分布式之 ParameterServerStrategy V1 目录 [源码解析] TensorFlow 分布式之 ParameterServerStrategy ...

  10. 『现学现忘』Git基础 — 24、Git中查看历史版本记录

    目录 1.查看详细的历史版本记录 2.简化显示历史版本记录 3.历史版本记录常用操作 (1)指定查看最近几次提交的内容 (2)以简单图形的方式查看分支版本历史 (3)翻页与退出 4.查看分支相关的版本 ...