UVA11093-Just Finish it up(思维)
Accept: 1225 Submit: 5637
Time Limit: 3000 mSec
Problem Description
Along a circular track, there are N gas stations, which are numbered clockwise from 1 up to N. At station i, there are pi gallons of petrol available. To race from station i to its clockwise neighbor one need qi gallons of petrol. Consider a race where a car will start the race with an empty fuel tank. Your task is to find whether the car can complete the race from any of the stations or not. If it can then mention the smallest possible station i from which the lap can be completed.
Input
First line of the input contains one integer T the number of test cases. Each test case will start with a line containing one integer N, which denotes the number of gas stations. In the next few lines contain 2∗N integers. First N integers denote the values of pis (petrol available at station i), subsequent N integers denote the value of qis (amount of patrol needed to go to the next station in the clockwise direction).
Output
Constraints
• T < 25
Sample Input
Sample Output
Case 1: Not possible
Case 2: Possible from station 4
题解:比较经典的问题,从1开始尝试,如果从p道p+1这一段走不到那就说明从2到p都不能走完全程,简单解释一下,如果能从1走到2,那么从1开始不会比从2开始更差,因为到2时的油>=0,因此1走不完,2更走不完,同理到p都走不完,直接从p+1开始试就好,复杂度线性。
#include <bits/stdc++.h> using namespace std; const int maxn = + ; int n, con = ;
int sup[maxn], req[maxn]; int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int iCase;
scanf("%d", &iCase);
while (iCase--) {
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &sup[i]);
}
for (int i = ; i < n; i++) {
scanf("%d", &req[i]);
} printf("Case %d: ", con++);
int st = ;
while (st < n) {
int tmp = st;
int cur = , T = n;
while (T--) {
cur += sup[tmp];
cur -= req[tmp];
if (cur < ) break;
tmp++;
tmp %= n;
}
if (T == -) break;
if (tmp + <= st) {
st = n;
break;
}
else st = tmp + ;
}
if (st == n) {
printf("Not possible\n");
}
else printf("Possible from station %d\n", st+);
}
return ;
}
UVA11093-Just Finish it up(思维)的更多相关文章
- 8-13 Just Finish it up uva11093
题意:环形跑道上有n n<=100000 个加油站 编号为1-n 第i个加油站可以加油pi加仑 从加油站i开到下一站需要qi加仑 你可以选择一个加油站作为起点 初始油箱为空 如果 ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Inno Setup设置在安装Finished页面,点击finish后打开网页
在安装的最后一个页面FinishPage中点击Finished然后打开一个网页 这个功能貌似很简单,不就是在点击finish按钮给它绑定事件,问题立马解决. 在普通的桌面应用程序开发中的确是这样做的, ...
- D. Eternal Victory(dfs + 思维)
D. Eternal Victory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- Photoshop、Illustrator思维导图笔记
半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.
- CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维
前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...
- 计算机程序的思维逻辑 (8) - char的真正含义
看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...
- 计算机程序的思维逻辑 (29) - 剖析String
上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...
随机推荐
- 全网最贴心webpack系列教程和配套代码
webpack-demos:全网最贴心 webpack 系列教程和配套代码 欢迎关注个人技术博客:godbmw.com.每周 1 篇原创技术分享!开源教程(webpack.设计模式).面试刷题(偏前端 ...
- idea护眼色设置
idea右侧编辑区设置护眼色
- idea编辑器快捷键调整
习惯了Eclipse中的删除快捷键,idea中的快捷键用着不是很适应,于是乎调整了下. idea编辑器快捷键调整: 默认:删除代码行:Ctrl+Y复制代码行:Ctrl+D在当前行之前添加一行: Ctr ...
- JS函数浅析(一)
1.万物皆为对象 提起函数首先要知道对象,而对象又是js数据类型中的一种,所以我们从头开始. 1)javascript数据类型有哪些? 原始数据类型:number,undefined ...
- wx-charts 微信小程序图表 -- radarChart C# .net .ashx 测试
radarChart:原始代码 new wxCharts({ canvasId: 'radarCanvas', type: 'radar', categories: ['1', '2', '3', ' ...
- CSS3 - @keyframes
语法 @keyframes animationname { keyframes-selector {css-styles;} } 值 描述 animationname 必需.定义动画的名称. keyf ...
- 解决ie6中png图片格式不兼容问题
在IE6中对图片格式png24支持度不高,如果使用的图片格式是png24,则会导致透明效果无法正常显示 解决方法: 1.可以使用png8来代替png24,即可解决问题,但是使用png8代替png24以 ...
- Python-Django 整合Django和jquery-easyui
整合Django和jquery-easyui by:授客 QQ:1033553122 测试环境 win7 64 Python 3.4.0 jquery-easyui-1.5.1 下载地址1:http: ...
- loadrunner 脚本录制-录制选项设置HTML-based URL-based Script
脚本录制-录制选项设置, HTML-based Script与URL-based Script by:授客 QQ:1033553122 Access:Vugen->Tool->Record ...
- Flask路由与蓝图Blueprint
需求分析: 当一个庞大的系统中有很多小模块,在分配路由的时候怎么处理呢?全部都堆到一个py程序中,调用@app.route? 显然这是很不明智的,因为当有几十个模块需要写路由的时候,这样程序员写着写着 ...