传送门

POJ

Vjudge

解题思路

可以首先预处理一下可能成为一条线路的所有方案,然后把这些可能的方案按照长度降序排序,即按照路线上的时间节点从多到少排序。

因为这样我们就可以先确定更多的时刻的状态,减少搜索深度。

然后加一个最优化剪枝:

如果当前花费加上未来的最少的花费不会优,就直接return掉。

然后因为我们把所有的路线都按照路上节点数降序排序,所以我们只要碰到第一个不会更优的就直接return。

细节注意事项

  • ans的初始化最好只要开到17,不然会跑得慢一些
  • 然后在 vjudgePOJ 上交的时候,要选的语言是 G++ 而不是 C++ 我居然CE了一次
Main.cpp
F:\temp\21004851.198535\Main.cpp(51) : error C2059: syntax error : '{'
F:\temp\21004851.198535\Main.cpp(51) : error C2143: syntax error : missing ';' before '{'
F:\temp\21004851.198535\Main.cpp(51) : error C2065: 'j' : undeclared identifier
F:\temp\21004851.198535\Main.cpp(51) : error C2065: 'j' : undeclared identifier
F:\temp\21004851.198535\Main.cpp(51) : error C2143: syntax error : missing ';' before '}'
  • 题面确实有点点的难捋清楚啊。。。

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} const int _ = 1926; int n, cnt[70], ans = 17, X;
struct node { int a, b, c; } t[_];
inline bool cmp(const node& x, const node& y) { return x.c > y.c; } inline bool check(int a, int b) {
for (rg int i = a; i < 60; i += b)
if (!cnt[i]) return 0;
return 1;
} inline void dfs(int i, int num) {
if (n == 0) { ans = min(ans, num); return ; }
for (rg int j = i; j <= X; ++j) {
if (num + n / t[j].c >= ans) return ;
if (check(t[j].a, t[j].b)) {
for (rg int k = t[j].a; k < 60; k += t[j].b) --n, --cnt[k];
dfs(j, num + 1);
for (rg int k = t[j].a; k < 60; k += t[j].b) ++n, ++cnt[k];
}
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n);
for (rg int x, i = 1; i <= n; ++i) read(x), ++cnt[x];
for (rg int i = 0; i < 30; ++i) {
if (!cnt[i]) continue;
for (rg int j = i + 1; i + j < 60; ++j)
if (check(i, j)) t[++X] = (node) { i, j, (59 - i) / j + 1 };
}
sort(t + 1, t + X + 1, cmp);
dfs(1, 0);
printf("%d\n", ans);
return 0;
}

完结撒花 \(qwq\)

「POJ1147」The Buses的更多相关文章

  1. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  2. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  3. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  4. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  5. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  6. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  7. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  8. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

  9. 「2014-3-13」Javascript Engine, Java VM, Python interpreter, PyPy – a glance

    提要: url anchor (ajax) => javascript engine (1~4 articles) => java VM vs. python interpreter =& ...

随机推荐

  1. 【快学SpringBoot】快速上手好用方便的Spring Cache缓存框架

    前言 缓存,在开发中是非常常用的.在高并发系统中,如果没有缓存,纯靠数据库来扛,那么数据库压力会非常大,搞不好还会出现宕机的情况.本篇文章,将会带大家学习Spring Cache缓存框架. 原创声明 ...

  2. IDEA 查看字节码

    参考:https://www.jianshu.com/p/18953ec8c0b7 打开工具栏 输入参数: 参数: $JDKPath$\bin\javap.exe -c $FileClass$ $Ou ...

  3. C++判断txt文件编码格式

    转载:https://blog.csdn.net/kikityan/article/details/89923808 记事本打开txt文件,然后另存,有四种编码格式可供选择,分别是:ANSI     ...

  4. Codeforces Round #588 (Div. 2)E(DFS,思维,__gcd,树)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[100007];vec ...

  5. floyd的魔改应用——洛谷P2419 [USACO08JAN]牛大赛Cow Contest 题解

    想找原题请点击这里:传送门 原题: 题目背景 [Usaco2008 Jan] 题目描述 N ( ≤ N ≤ ) cows, conveniently numbered ..N, are partici ...

  6. 并发队列之ArrayBlockingQueue

    上一篇我们说了并发队列中的LinkedBlockingQueue队列,这次我们看看ArrayBlockingQueue,看看名字,我们想象一下LinkedList和ArrayList的区别,我们可以知 ...

  7. 软件架构,WEB - REST架构,RESTful API

    参考 https://www.zhihu.com/question/27785028/answer/48096396 wiki太学术化了 http://www.ruanyifeng.com/blog/ ...

  8. robot framework 接口post请求需要加headers

    说明:当你用RF进行post接口测试时候,那么需要加个headers=Content-Type=application/x-www-form-urlencoded,要不然会请求不成功的.

  9. LoadRunner的参数化

    好久不用loadrunner,以前的东西又都还给百度了,今天心血来潮,把参数化搞了一下 Action() { web_url("WebTours", "URL=http: ...

  10. spring boot 是如何启动 tomcat

    Spring boot 的启动类启动后,tomcat 容器.Spring mvc .spring 事务等等第三方依赖也已经自动启动,那么spring boot 是如何启动的第三方依赖? 以spring ...