【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$次, ...
随机推荐
- Java中last_insert_id的使用
last_insert_id的作用是:在当前表中的主键是自增时,插入一条新记录的同时使用last_insert_id可以获取当前的新记录的主键id. 下面是一个例子: import java.sql. ...
- 九九乘法表---for循环的嵌套
package com.zuoye.test;//控制台输出九九乘法表public class Jiujiu { public static void main(String[] args) { in ...
- 【Linux】七种运行级别
运行级别:即系统的运行模式. 级别类型: 0:关机状态. 1:单用户模式. 2:字符界面的多用户模式(不支持网络). 3:字符界面的多用户模式(运行最完整的模式). 4:未分配使用,系统保留. 5:图 ...
- phpmyadmin搭建
phpadmin配置: 一.phpadmin安装及配置 1.解压phpadmin压缩包,并复制到 /usr/local/apache2/htdocs目录,重命名为dataManage 2.进入data ...
- SmartUpload实现文件上传
(一)SmartUpload组件简介 SmartUpload组件 专门用于实现文件上传及下载的免费组件 (二)SmartUpload组件特点 使用简单:编写少量代码,完成上传下载功能 能够控制上传 ...
- dubbo之本地调用
本地调用 本地调用使用了 injvm 协议,是一个伪协议,它不开启端口,不发起远程调用,只在 JVM 内直接关联,但执行 Dubbo 的 Filter 链. 配置 定义 injvm 协议 <du ...
- java StringUtils
/** * */ package com.sign.utils; import java.util.regex.Pattern; /** * @author Administrator * creat ...
- vue向数组中动态添加数据
vue中数据更新通过v-model实现,向数组中添加数据通过push()实现,向shortcuts数组中动态添加newShortcut对象中的title和action this.shortcuts.p ...
- python 字符串模糊匹配 Fuzzywuzzy
Python提供fuzzywuzzy模块,不仅可用于计算两个字符串之间的相似度,而且还提供排序接口能从大量候选集中找到最相似的句子. (1)安装 pip install fuzzywuzzy (2)接 ...
- 初识 Django
HTTP协议 HTTP(hypertext transport protocol),即超文本传输协议.这个协议详细规定了浏览器和万维网服务器之间互相通信的规则. HTTP就是一个通信规则,通信规则规定 ...