https://vjudge.net/problem/UVA-11093

题意:环形跑道上有n个加油站,编号为1~n。第i个加油站可以加油pi加仑,从加油站i开到下一站需要qi加仑汽油。输出最小的起点,使得可以走完一圈后回到起点。

思路:直接枚举。注意剪枝就可以了,如从1号加油站出发,开到加油站p前没油了,那么2,3,4...p-1肯定不是解。

 #include<iostream>
using namespace std; const int maxn = + ;
int n;
int ans;
int p[maxn];
int q[maxn]; bool solve()
{
int pas;
int ok = ;
for (int i = ; i < n; i++)
{
pas = ;
for (int j = ; j <= n; j++)
{
int t = (i + j) % (n + );
pas += p[t];
pas -= q[t];
if (pas < )
{
if (t>=i) { i = t; break; } //t还没有作为过起点
else return false; //t已经作为过起点
}
if (j == n && pas >= ) ok = ;
}
if (ok) { ans = i; return true; }
}
return false;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int t, kase = ;
cin >> t;
while (t--)
{
cin >> n;
for (int i = ; i < n; i++)
cin >> p[i];
for (int i = ; i < n; i++)
cin >> q[i];
if (solve()) cout << "Case " << ++kase << ": Possible from station " << ans+ << endl;
else cout << "Case " << ++kase << ": Not possible" << endl;
}
return ;
}

UVa 11093 环形跑道(模拟)的更多相关文章

  1. UVA - 11093 Just Finish it up(环形跑道)(模拟)

    题意:环形跑道上有n(n <= 100000)个加油站,编号为1~n.第i个加油站可以加油pi加仑.从加油站i开到下一站需要qi加仑汽油.你可以选择一个加油站作为起点,起始油箱为空(但可以立即加 ...

  2. UVA 11093 Just Finish it up 环形跑道 (贪心)

    有一个环形跑道,上面有n个加油站,到i号加油站可以加pi的油,跑到下一站要花费qi的油,起点任意选,问是否有一个起点可跑完整个跑道. 从i开始跑,如果遇到某个站j不能跑了,那么从i到j之间的站开始跑, ...

  3. 【uva 11093】Just Finish it up(算法效率--贪心)

    题意:环形跑道上有N个加油站,编号为1~N.第 i 个加油站可以加油Ai加仑,从加油站 i 开到下一站需要Bi加仑汽油.问可作为起点走完一圈后回到起点的最小加油站编号. 解法:我们把每个加油站的Ai, ...

  4. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVA 1156 - Pixel Shuffle(模拟+置换)

    UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...

  6. UVA 12050 - Palindrome Numbers 模拟

    题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...

  7. Uva 679 Dropping Balls (模拟/二叉树的编号)

    题意:有一颗二叉树,深度为D,所有节点从上到下从左到右编号为1,2,3.....在结点一处放一个小球,每个节点是一个开关,初始全是关闭的,小球从顶点落下,小球每次经过开关就会把它的状态置反,现在问第k ...

  8. ●UVa 1589 Xiangqi(模拟)

    ●赘述题意 给出一个中国象棋残局,告诉各个棋子的位置,黑方只有1枚“将”,红方有至少2枚,至多7枚棋子,包含1枚“帅G”,和若干枚“车R”,“马H”,“炮C”.当前为黑方的回合,问黑方的“将”能否在移 ...

  9. 【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题

    题意:阅读理解难度一道比一道难orz.手摸了好久样例 题解: 读入:大循环用getline读入header顺便处理一下,  里面再写两重循环,外层一次读三个串,内层一次读num个串. 之后就查表,线性 ...

随机推荐

  1. 类似CFS程式发布注意事项

    1.CFS 此AP 程式的验证方式为Forms 验证.需要在IIS 中做如下设置(Forms 身份验证,配套的Web.config 中要有对应节点代码,后台代码中要有获取方式) 2.Forms 身份验 ...

  2. Comparable和Comparator的使用

    1:对象实现Comparable, 那么对象就具有了比较功能 package comparableAndComparator; import java.util.Collections; import ...

  3. AngularJS 模型

    ng-model 指令将HTML 控制器(input, select, textarea)的值 和 应用程序数据进行绑定. ng-model 指令 ng-model 指令可以将输入域的值与 Angul ...

  4. [LeetCode] 697. Degree of an Array_Easy tag: Hash Table

    Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...

  5. javascript unicode与GBK2312(中文)编码转换示例

    一个javascript的unicode与GBK2312编码相互转换的方法. 代码: var GB2312UnicodeConverter = {     ToUnicode: function (s ...

  6. Quick Look at the Air Jordan 32

    A color with 25 years of history in the Air Jordan line will once again leave its mark on the Air Jo ...

  7. SQL Server 2008 R2 超详细安装图文教程

    一.下载SQL Server 2008 R2安装文件 ed2k://|file|cn_sql_server_2008_r2_enterprise_x86_x64_ia64_dvd_522233.iso ...

  8. JavaScript DOM2

    1.Window.history:window.open打开网页的方式必须是_self window.history.back()后退 Window.history.forward()前进 <b ...

  9. ServiceStack DotNet Core前期准备

    下载DotNet Core SDK 下载地址:https://dotnet.microsoft.com/download. 安装完成之后通过cmd的命令行进行确认. 官方自带的cmd比较简陋,可以用c ...

  10. Vert.x

    Vert.x是一个基于JVM.轻量级.高性能的应用平台,非常适用于最新的移动端后台.互联网.企业应用架构.Vert.x基于全异步Java服务器Netty,并扩展出了很多有用的特性. 同时支持多种编程语 ...