嘟嘟嘟




正如某题解所说,这题很有误导性:我就一直在想凸包。

随便一个数据,就能把凸包hack掉:

这样我们的点G就gg了。




所以正解是什么呢?dp。

题解看这位老哥的吧,我感觉挺好懂的:题解 P4563 【[JXOI2018]守卫】

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 5e3 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n;
struct Point
{
ll x, y;
In Point operator + (const Point& oth)const
{
return (Point){x + oth.x, y + oth.y};
}
In Point operator - (const Point& oth)const
{
return (Point){x - oth.x, y - oth.y};
}
In ll operator * (const Point& oth)const
{
return x * oth.y - y * oth.x;
}
}p[maxn]; int dp[maxn][maxn]; int main()
{
n = read();
for(int i = 1; i <= n; ++i) p[i].x = i, p[i].y = read();
int ans = 0;
for(int i = 1; i <= n; ++i)
{
dp[i][i] = 1; ans ^= 1;
int sum = 1, pos = 0;
for(int j = i - 1; j; --j)
{
if(!pos || (p[pos] - p[i]) * (p[j] - p[i]) < 0)
sum += min(dp[j + 1][pos - 1], dp[j + 1][pos]), pos = j;
dp[j][i] = sum + min(dp[j][pos - 1], dp[j][pos]);
ans ^= dp[j][i];
}
}
write(ans), enter;
return 0;
}

[JXOI2018]守卫的更多相关文章

  1. 【BZOJ5324】[JXOI2018]守卫(动态规划)

    [BZOJ5324][JXOI2018]守卫(动态规划) 题面 BZOJ 洛谷 题解 既然只能看到横坐标在左侧的点,那么对于任意一个区间\([l,r]\)而言,\(r\)必须被选. 假设\(r\)看不 ...

  2. BZOJ5324 JXOI2018守卫(区间dp)

    对于每个区间[l,r],显然右端点r是必须放置守卫的.考虑其不能监视到的点,构成一段段区间.一个非常显然但我就是想不到的性质是,对于这样的某个区间[x,y],在(y+1,r)内的点都是不能监视到这个区 ...

  3. 洛谷P4563 [JXOI2018]守卫(dp)

    题意 题目链接 Sol 非常有意思的题目. 我们设\(f[l][r]\)表示区间\([l,r]\)的答案. 显然\(r\)位置一定有一个保镖 同时不难观察到一个性质:拿\([1, n]\)来说,设其观 ...

  4. JXOI2018守卫 区间DP

    链接 https://loj.ac/problem/2545 思路 f[i][j]表示i到j区间的最小监视人数 可以预处理出来g[i][j],表示i能否监视到j (其实预处理的关系不大,完全可以直接判 ...

  5. [洛谷P4563][JXOI2018]守卫

    题目大意:有一段$n(n\leqslant5\times10^3)$个点的折线,特殊点可以覆盖它以及它左边的它可以“看见”的点(“看见”指连线没有其他东西阻挡).定义$f_{l,r}$为区间$[l,r ...

  6. BZOJ5324 & 洛谷4563 & LOJ2545:[JXOI2018]守卫——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5324 https://www.luogu.org/problemnew/show/P4563 ht ...

  7. BZOJ5324 JXOI2018 守卫

    传送门 这是我见过的为数不多的良心九怜题之一 题目大意 给定一段$n$个点构成的折线,第$i$个折点的坐标是$(i,h_i)$,你可以在$i$点放置一个视野,定义$i$能看到$j$当且仅当$i$处有视 ...

  8. yyb省选前的一些计划

    突然意识到有一些题目的计划,才可以减少大量查水表或者找题目的时间. 所以我决定这样子处理. 按照这个链接慢慢做. 当然不可能只做省选题了. 需要适时候夹杂一些其他的题目. 比如\(agc/arc/cf ...

  9. 【JXOI2018】守卫

    [JXOI2018]守卫 参考题解:https://blog.csdn.net/dofypxy/article/details/80196942 大致思路就是:区间DP.对于\([l,r]\)的答案, ...

随机推荐

  1. Hibernate入门(二)——hibernateAPI详解

    Hibernate API 详解 1.Configuration 功能:配置加载类,用于加载主配置,orm元数据加载 .创建: Configuration conf = new Configurati ...

  2. js操作css样式,null和undefined的区别?

    1.js操作css的样式 div.style.width="100px"在div标签内我们添加了一个style属性,并设定了width值.这种写法会给标签带来大量的style属性, ...

  3. 新浪IP库地址

    新浪IP库地址 http://int.dpool.sina.com.cn/iplookup/iplookup.php

  4. react学习(三)之生命周期/refs/受控组件 篇

    挂载/卸载 //在类组件中 class Clock extends React.Component { constructor(props) { super(props); this.state = ...

  5. 一、Composer下载安装

    1.composer下载 英文网站:https://getcomposer.org/ 中文镜像:https://www.phpcomposer.com/ 2.composer安装 • win下安装图文 ...

  6. C#反射、方法调用、自动调用方法、根据按钮名称调用方法、C#按钮权限管理

    根据按钮名称,直接调用方法,适用于用户对按钮的操作权限管理. /// <summary> /// 菜单按钮点击事件 /// </summary> void usrMenu1_U ...

  7. Suricata规则编写——常用关键字

    本篇转载自:http://blog.csdn.net/wuyangbotianshi/article/details/44775181 1.简介 现在的NIDS领域snort一枝独秀,而suricat ...

  8. eclipse安装其他颜色主题包

    eclipse安装其他颜色主题包: 用Help-Install new software安装的时候,work with的URL是 http://eclipse-color-theme.github.c ...

  9. 四则运算 Java 杨辉鹏,郑冠华

    四则运算 Java 杨辉鹏,郑冠华 GitHub链接:https://github.com/yanghuipeng/arithmetic 项目相关要求 使用 -n 参数控制生成题目的个数,例如 -n ...

  10. Scala抽象类型

    package big.data.analyse.scala import scala.io.{BufferedSource, Source} /** * 抽象类型 * Created by zhen ...