UVA 11093 Just Finish it up(模拟|想法)
来源:互联网 发布:javascript教程谁的好 编辑:程序博客网 时间:2024/06/17 01:11
题目链接
题意
环形跑道上有n个加油站,第i个加油站可以加Pi汽油,从i加油站开到下一个加油站需要Qi汽油。任务是选择一个加油站作为起点,可以走完一圈后回到起点。
解决
从1开始枚举,以每一个点作为起点,如果可以就输出答案;如果当前节点不可以作为出发点,说明到了某一个点tmp不能再继续向下走了,那么从起点到tmp的这些点也肯定不能作为起点。
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;int P[2*maxn],Q[2*maxn];int main(){ int cases,c=1; scanf("%d",&cases); while(cases--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&P[i]); P[i+n]=P[i]; //这里用2*n的数组代替环路 } for(int i=1;i<=n;i++){ scanf("%d",&Q[i]); Q[i+n]=Q[i]; } printf("Case %d: ",c++); int bg=1; bool ok=false; while(bg<=n&&!ok) { int tmp=bg; int ans=0; while(1){ ans+=P[tmp]; ans-=Q[tmp]; if(ans<0) break; tmp++; if(tmp==bg+n){ //绕了一圈又回到出发点 printf("Possible from station %d\n",bg); ok=true; break; } } bg=tmp+1; } if(!ok) printf("Not possible\n"); }}
阅读全文
0 0
- UVA 11093 Just Finish it up(模拟|想法)
- UVa 11093 Just Finish it up 模拟
- UVA 11093 Just Finish it up(模拟题)
- UVA-11093-Just Finish It Up
- UVA - 11093 Just Finish it up 环路
- uva 11093 just finish it up
- UVa 11093 - Just Finish it up
- UVa 11093 - Just Finish it up
- Uva - 11093 - Just Finish it up
- uva 11093Just Finish it up
- UVA 11093(p246)----Just Finish it up
- UVA - 11093 - Just Finish it up
- UVa OJ 11093 - Just Finish it up
- UVA 11093Just Finish it up
- UVA 11093 Just Finish it up
- UVA-11093 Just Finish it up
- Just Finish it up UVA
- uva 11093 Just Finish it up (环形跑道水题_模拟)
- 关于Properties的一些方法
- Kotlin 是一个基于 JVM 的新的编程语言
- 95. Unique Binary Search Trees II
- JAVA工具类(7)---MD5加密工具类
- P1190 接水问题 优先队列实现
- UVA 11093 Just Finish it up(模拟|想法)
- java异常体系
- 校招编程题目(1) C++:括号匹配方案(京东)
- Eclipse中安装Spring插件
- 为什么会有 Memcache 和 memcached
- Linux环境下部署jasperreport出现net.sf.jasperreports.engine.util.JRFontNotFoundException
- java2
- list、tuple和dict的for循环遍历
- 数据库基础知识总结