Contest2892 - 2021个人训练赛第39场

Rope Folding

时间限制: 1 Sec 内存限制: 64 MB

题目描述
Farmer John has a long rope of length L (1 <= L <= 10,000) that he uses for various tasks around his farm. The rope has N knots tied into it at various distinct locations (1 <= N <= 100), including one knot at each of its two endpoints.

FJ notices that there are certain locations at which he can fold the rope back on itself such that the knots on opposite strands all line up exactly with each-other:

Please help FJ count the number of folding points having this property. Folding exactly at a knot is allowed, except folding at one of the endpoints is not allowed, and extra knots on the longer side of a fold are not a problem (that is, knots only need to line up in the areas where there are two strands opposite each-other). FJ only considers making a single fold at a time; he fortunately never makes multiple folds.

输入

  • Line 1: Two space-separated integers, N and L.
  • Lines 2…1+N: Each line contains an integer in the range 0…L specifying the location of a single knot. Two of these lines will always be 0 and L.
    输出
  • Line 1: The number of valid folding positions.
    样例输入
5 10
0
10
6
2
4

样例输出

4

**题意:**有个线段,上面有结点,求在几个位置可以让俩边结点重合,一段超出部分的结点不算。允许完全在一个结处折叠,但不允许在一个端点折叠,求有效折叠位置的数量。
**思路:**枚举。因为不是每个折叠位置都是整数位置,可能有0-1之间0.5的情况。
代码:

#include<iostream>
using namespace std;
int n,len,s=0;
int a[11000];
int fun2(int x)
{int l=x,r=x+1;//两点之间,eg:0.5 while(l>=0&&r<=len){if(a[l]!=a[r]) return 0;//如果两边结点没有重回,停止,该点不能折叠 l--;r++;}return 1;//可以,加一
}
int fun1(int x)
{int l=x,r=x;while(l>=0&&r<=len){if(a[l]!=a[r]) return fun2(x);l--;r++;}if(fun2(x)==1) return 2;//如果在两点间的中点也可以,共两个 return 1;//该点可以,加一
}
int main()
{cin>>n>>len;for(int i=1;i<=n;i++){int x;cin>>x;a[x]=1;//如果该位置有结点,a[x]=1,标记一下,与没有节点的区分 }s+=fun2(0);for(int i=1;i<len;i++){s+=fun1(i);}cout<<s;return 0;
}

Rope Folding相关推荐

  1. UPC第38,39,40场部分题解

    UPC第38,39,40场部分题解 第38场 A. Bovine Alliance Description Bessie and her bovine pals from nearby farms h ...

  2. Splay ---- 2018牛客多校第三场 区间翻转搞区间位移 或者 rope可持久化块状链表

    题目链接 题目大意: 就是每次把牌堆中若干个连续的牌放到堆顶,问你最后牌的序列. 解题思路: Splay 区间翻转的模板题: 对于一个区间[1,2,3,4,5,6,7,8][1,2,3,4,5,6,7 ...

  3. C++官方自带可持久化平衡树rope的3000行源码

    C++官方rope3000行源码 // SGI's rope class -*- C++ -*-// Copyright (C) 2001-2015 Free Software Foundation, ...

  4. c++自带的可持久化平衡树?rope大法好!(超详细解答 + 5道例题讲解,可直接替代可持久化的线段树、并查集、平衡树!)

    整理的算法模板合集: ACM模板 目录 c++自带的可持久化平衡树?rope大法好! 1. 声明 2. 支持操作 char类型的rope int类型的rope 3. 具体的细节 4. "可持 ...

  5. 【每日训练】2020/11/9(Splay ?rope大法好!、数论、构造补图)

    整理的算法模板合集: ACM模板 目录 1. 牛客Shuffle Cards 2.CF992B Nastya Studies Informatics 3.CF990D Graph And Its Co ...

  6. 《搬砖日记》Obi Rope插件的简单使用

    今天介绍一个Unity绳子插件Obi Rope的简单使用 先分享一下插件: 链接:https://pan.baidu.com/s/1XQp3mYxTRfvXwsU_Z_9ILw 提取码:pw08 进入 ...

  7. Codeforces Gym 101473D Folding Machine (暴力搜索)

    题目连接: http://codeforces.com/gym/101473/attachments 原先以为按照这个复杂度还要剪一下支,没想到暴力dfs完全可以通过. 代码: #include &l ...

  8. 【可持久化线段树?!】rope史上最全详解

    https://www.luogu.org/problemnew/show/P3919 看到上面链接中的题时,我在学会可持久化线段树的同时,第一次学会了一个非常屌(cai)的STL大法--rope!! ...

  9. [HDU 4344]Mark the Rope(Pollard_rho+Miller_Rabin)

    Description Eric has a long rope whose length is N, now he wants to mark on the rope with different ...

最新文章

  1. 斯坦福李飞飞团队「最惨」在读博士:论文被拒,项目被砍,本文教你如何正视失败!...
  2. py2与py3的区别
  3. Source Insight 4怎么取消函数结束提示字符
  4. 多少秒算长镜头_自从搞烘焙后,遇到烘焙模具换算,秒变数学渣...
  5. console.log打印没有效果
  6. 力扣172.阶乘后的零
  7. 安卓弹性刷新通用版—支持任何view上下刷新均有弹性效果
  8. java restlet 教程_java – Restlet Protocol.FILE用法
  9. MIUI ROM for Milestone 刷机教程
  10. 无需插件只使用浏览器下载b站视频
  11. linux更换steam目录,终于可以在Linux上愉快地玩耍Steam啦
  12. 使用excel、python、tableau对招聘数据进行数据处理及可视化分析
  13. in作为介词的用法_介词in重要用法归纳
  14. 引用echarts报错Cannot read property ‘init‘ of underfined
  15. php 商铺附近定位,php 地图标注百度地图添加商铺
  16. 服务器域共享文件夹,访问域共享文件夹
  17. 空间计量 python_空间计量经济学与Stata实现
  18. Allegro学习笔记
  19. 《 Python程序设计项目案例》— 用Python开发的基于TCP通讯协议的私人聊天室 (期末大作业、结课作业、课程设计、毕业设计)
  20. (20)全民小视频引流脚本模块化开发14-给脚本添加本地授权By飞云脚本学院

热门文章

  1. 无线AP和无线路由器区别
  2. 计算机网络技术在医院的应用,计算机网络化应用在医院管理中的作用
  3. WinXP无法删除文件夹,访问被拒绝
  4. IP网络主动测评系统——IT运维人员的好帮手
  5. 华为通用软件开发实习生面试题
  6. Go mockito 使用说明 (github/mockey)
  7. 借贷记账法下的账户结构、借贷记账法的记账规则、借贷记账法下的账户对应关系与会计分录
  8. 【大咖说*对话生态】——阿里云携手VMware,助力企业数字化转型
  9. 神州交换机路由器AC和AP基本配置
  10. 全媒舍:溯源媒体宣传方式和普通宣传方式有一定差别