POJ1167 The Buses
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6234 | Accepted: 1698 |
Description
- Buses on the same route arrive at regular intervals from 12:00 to 12:59 throughout the entire hour.
- Times are given in whole minutes from 0 to 59.
- Each bus route stops at least 2 times.
- The number of bus routes in the test examples will be <=17.
- Buses from different routes may arrive at the same time.
- Several bus routes can have the same time of first arrival
and/or time interval. If two bus routes have the same starting time and
interval, they are distinct and are both to be presented.
Find the schedule with the fewest number of bus routes that must
stop at the bus stop to satisfy the input data. For each bus route,
output the starting time and the interval.
Input
program is to read from standard input. The input contains a number n (n
<= 300) telling how many arriving buses have been noted, followed by
the arrival times in ascending order.
Output
Sample Input
17
0 3 5 13 13 15 21 26 27 29 37 39 39 45 51 52 53
Sample Output
3
Source
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int ct[];//ct[i]表示第i分钟到达的车数
int n,ans,tp;//车数 答案 总备选线路数
struct node{
int s;//第一次到达时间
int j;//发车间隔
int t;//需要车数
}p[];
int cmp(node a,node b){
return a.t>b.t;
}
bool test(int s,int ti){//s_起始时间 ti_间隔时间
for(int i=s;i<;i+=ti)
if(!ct[i])return false;
return true;
}
void dfs(int t,int now){
int i,j,k,tmp;
if(n==){
if(now<ans)ans=now;
return;
}
for(i=t;i<=tp && p[i].t>n;i++);//寻找合适线路,排除需要车数比剩余车数大的线路
for(k=i;k<=tp;k++){
if(now+n/p[k].t>=ans)return;//剪枝
if(test(p[k].s,p[k].j)){
tmp=p[k].j;
for(j=p[k].s;j<;j+=tmp){
ct[j]--;
n--;
}
dfs(k,now+);
for(j=p[k].s;j<;j+=tmp){
ct[j]++;
n++;
}
}
}
}
int main(){
scanf("%d",&n);
int i,j,a;
for(i=;i<=n;i++){
scanf("%d",&a);
ct[a]++;
}
tp=;
for(i=;i<=;i++){
if(!ct[i])continue;
for(j=i+;j<=-i;j++){
if(test(i,j)){
tp++;
p[tp].s=i;
p[tp].j=j;
p[tp].t=+(-i)/j;
}
}
}
sort(p+,p+tp+,cmp);
ans=;
dfs(,);
printf("%d",ans);
return ;
}
POJ1167 The Buses的更多相关文章
- CF459C Pashmak and Buses (构造d位k进制数
C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- ural 1434. Buses in Vasyuki
1434. Buses in Vasyuki Time limit: 3.0 secondMemory limit: 64 MB The Vasyuki University is holding a ...
- UVA12653 Buses
Problem HBusesFile: buses.[c|cpp|java]Programming competitions usually require infrastructure and or ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- Problem J: Island Buses
主要题意是:大海之间有岛,有的岛之间有桥,问你岛的个数,桥的个数,以及没有桥联通岛的个数,其中最后一次输入的没有回车,不注意的话最后一次会被吞,第二,桥的两端的标记是“X”(X也代表陆地),“X”的四 ...
- Codeforces 665A. Buses Between Cities 模拟
A. Buses Between Cities time limit per test: 1 second memory limit per test: 256 megabytes input: s ...
- Educational Codeforces Round 12 A. Buses Between Cities 水题
A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...
随机推荐
- java基础—接口概念
一.接口的概念 JAVA是只支持单继承的,但现实之中存在多重继承这种现象,如“金丝猴是一种动物”,金丝猴从动物这个类继承,同时“金丝猴是一种值钱的东西”,金丝猴从“值钱的东西”这个类继承,同时“金丝猴 ...
- Nginx: ubuntu系统上如何判断是否安装了Nginx?
问题描述:ubuntu系统上,如何查看是否安装了Nginx? 解决方法:输入命令行:ps -ef | grep nginx master process后面就是Nginx的安装目录. 延伸:1. 如何 ...
- Mutations-freecodecamp算法题目
Mutations(比较字符串) 要求 如果数组第一个字符串元素包含了第二个字符串元素的所有字符,函数返回true. 不用考虑大小写和字符顺序 思路 将数组中的两个字符串小写化 将第二个数组元素(第二 ...
- 【莫队】bzoj4542: [Hnoi2016]大数
挺有意思的,可以仔细体味一下的题:看白了就是莫队板子. Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小 ...
- pandas学习series和dataframe基础
PANDAS 的使用 一.什么是pandas? 1.python Data Analysis Library 或pandas 是基于numpy的一种工具,该工具是为了解决数据分析人物而创建的. 2.p ...
- mysql数据库使用mybatis 插入数据时返回主键
为了体现题目,特指的是mysql,先贴上代码: <insert id="saveBizProdOrderDetail" useGeneratedKeys="true ...
- 使用Spring MVC后实现一个BaseController
使用Spring MVC技术后,可以实现一个基类的Controller类来分装一些MVC常用的方法,其他的Controller都继承自这个BaseController,这样在使用常用的方法时将会变得非 ...
- CSS基础:block,inline和inline-block
css的display属性是前端开发中非常常见的属性,本文简单介绍下其中比较常用的属性值,即block.inline和inline-block. HTML组件中呈现一片空白区域的组件都可当盒模型(bo ...
- Juicer 轻量级javascript模板引擎
juicer是一个javascript轻量级模板引擎. 使用方法 编译模板并根据数据立即渲染出结果 1 juicer(tpl, data); 仅编译模板暂不渲染,返回一个可重用的编译后的函数 1 va ...
- 15.Yii2.0框架where单表查询
目录 新建控制器 HomeController.php 新建model article.php 新建控制器 HomeController.php D:\xampp\htdocs\yii\control ...