【IOI 1994】 The Buses
【题目链接】
http://poj.org/problem?id=1167
【算法】
深度优先搜索 + 迭代加深
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 1010 struct info
{
int opt,fir;
} b[MAXN]; int i,n,g,mx;
int a[MAXN],h[MAXN]; inline bool check()
{
for (i = ; i <= g; i++)
{
if (b[i].opt == )
return false;
}
return true;
}
inline bool IDDFS(int dep,int m)
{
int i,d,tmp,e;
if (dep > n)
{
if (check())
return true;
else return false;
}
if (h[a[dep]] <= ) return IDDFS(dep+,m);
for (i = ; i <= m; i++)
{
if (b[i].opt == )
{
d = a[dep] - b[i].fir;
if (d <= b[i].fir) continue;
b[i].opt = ;
tmp = a[dep];
while (tmp <= mx && h[tmp] > )
{
h[tmp]--;
tmp += d;
}
if (tmp > mx)
{
if (IDDFS(dep+,m))
return true;
}
b[i].opt = ;
e = tmp - d;
tmp = a[dep];
while (tmp <= e)
{
h[tmp]++;
tmp += d;
}
}
}
if (m >= g) return false;
if ( * a[dep] >= ) return false;
m++;
h[a[dep]]--;
b[m].opt = ;
b[m].fir = a[dep];
if (IDDFS(dep+,m))
return true;
h[a[dep]]++;
return false;
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++)
{
scanf("%d",&a[i]);
if (a[i] > mx)
mx = a[i];
h[a[i]]++;
}
for (i = ; i <= ; i++)
{
g = i;
if (IDDFS(,))
break;
}
printf("%d\n",g); return ; }
【IOI 1994】 The Buses的更多相关文章
- 【IOI 1998】 Picture
[题目链接] 点击打开链接 [算法] 线段树扫描线求周长并 [代码] #include <algorithm> #include <bitset> #include <c ...
- 【IOI 1996】 Network of Schools
[题目链接] 点击打开链接 [算法] 对于第一问,将这个图缩点,输出出度为零的点的个数 对于第二问,同样将这个图缩点,输出入度为零.出度为零的点的个数的最大值 [代码] #include <al ...
- 【IOI 2011】Race
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2599 [算法] 点分治 [代码] #include<bits/stdc++.h ...
- 【IOI 2018】Werewolf 狼人
虽然作为IOI的Day1T3,但其实不是一道很难的题,或者说这道题其实比较套路吧. 接下来讲解一下这个题的做法: 如果你做过NOI 2018的Day1T1,并且看懂了题面,那你很快就会联想到这道题,因 ...
- 【IOI 2018】Combo 组合动作(模拟,小技巧)
题目链接 IOI的签到题感觉比NOI的签到题要简单啊,至少NOI同步赛我没有签到成功…… 其实这个题还是挺妙妙的,如果能够从题目出发,利用好限制,应该是可以想到的做法的. 接下来开始讲解具体的做法: ...
- 【UOJ #29】【IOI 2014】holiday
http://uoj.ac/problem/29 cdq四次处理出一直向左, 一直向右, 向左后回到起点, 向右后回到起点的dp数组,最后统计答案. 举例:\(fi\)表示一直向右走i天能参观的最多景 ...
- 【BZOJ 2599】【IOI 2011】Race 点分治
裸的点分治,然而我因为循环赋值$s$时把$i <= k$写成$i <= n$了,WA了好长时间 #include<cstdio> #include<cstring> ...
- 【IOI 2018】Highway 高速公路收费
这是一道极好的图论题,虽然我一开始只会做$18$分,后来会做$51$分,看着题解想了好久才会做(吐槽官方题解:永远只有一句话),但这的确是一道好题,值得思考,也能启发思维. 如果要讲这道题,还是要从部 ...
- 【IOI 2018】Doll 机械娃娃
我感觉这个题作为Day2T1,有一定的挑战性.为$Rxd$没有完成这道题可惜. 我觉得这道题,如果按照前几个部分分的思路来想,就有可能绕进错误的思路中.因为比如说每个传感器最多只在序列中出现$2$次, ...
随机推荐
- var _this = this 是干什么的
因为JS可以多层嵌套代码可能下面还可以再嵌一个方法引用this就会变成子方法控制的对象如果需要上级的对象在没有参数的情况下前面前提做了一个临时变量_this可以保存上级对象子方法中就可以用_this来 ...
- for 循环练习题(2)
一张纸的厚度是0.0001米,将纸对折,对折多少次厚度超过珠峰高度8848米 var x=0.0001; for(var a=1;true;a++){ x=x*2; if (x>8848) { ...
- 【Oracle】恢复重做日志组
我们在Oracle的日常运维中,有可能会遇到重做日志组丢失的情况.下面我将模拟丢失不同状态的日志组,并分别给出解决办法: 重做日志有以下几种状态,如下: - CURRENT:此状态表示正在被 LGW ...
- BSGS-BabyStepGiantStep算法+拓展
学习数学真是一件赛艇的事. BSGS名字听起来非常有意思,力拔山兮气盖世,北上广深,小步大步...算法其实更有意思,它是用来求解一个方程的 A^x ≡ B (mod P) 是不是特别眼熟,有几个式子长 ...
- Linux命令小记
以下说法都是基于普通用户的角度,如果是root,可能会有不同. (1)rm -r或-R选项:递归删除目录及其内容(子目录.文件) rm默认无法删除目录,如果删除空目录,可以使用-d选项.如果目录非空, ...
- 【技术累积】【点】【java】【19】访问权限
java中的四种访问权限 范围如下表 权限 类内 同包 不同包子类 不同包非子类 Public ✔️ ✔️ ✔️ ✔️ 默认(Default) ✔️ ✔️ ️ Protected ✔️ ✔️ ✔️ P ...
- iproute2常用命令
#常用命令 ip link show #显示链路 ip addr show #显示地址(或ifconfig) ip route show #显示路由(route -n) ip neigh show # ...
- Jsp页面中常用的EL表达式
首先引入标签 <%@ page language="java" contentType="text/html; charset=utf-8" pageE ...
- Docker拉取images时报错Error response from daemon
docker拉取redis时,抛出以下错误: [master@localhost ~]$ docker pull redis Using default tag: latest Error respo ...
- Cache占用过多内存导致Linux系统内存不足问题排查
问题描述 Linux服务器内存使用量超过阈值,触发报警. 问题排查 首先,通过free命令观察系统的内存使用情况,显示如下: total used free shared buffers cached ...