New Year Transportation(水)
New Year Transportation Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.
Input
The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.
The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output
If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".
Sample Input
8 4
1 2 1 2 1 2 1
YES
8 5
1 2 1 2 1 1 1
NO
Hint
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
题解:水题,就是i+a[i]能否到达。。。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <malloc.h>
using namespace std;
typedef struct type_data{
int *a;
int n, t;
int ans;
type_data(){
ans = ;
}
}type_data;
void work(void *arg);
void *winit(){
type_data* dt = (type_data *)malloc(sizeof(type_data));
dt->a = (int *)malloc(sizeof(int) * 3e4 + );
return (void *)dt;
}
void *wfinish(type_data* dt){
delete(dt->a);
dt->a = NULL;
delete(dt);
dt = NULL;
}
void io(type_data* dt){
while(~scanf("%d%d", &dt->n, &dt->t)){
for(int i = ; i < dt->n; i++)
scanf("%d", dt->a+i);
work((void*)dt);
if(dt->ans == )
puts("YES");
else if(!dt->ans)
puts("NO");
else
puts("work error");
}
}
void work(void* arg){
type_data* dt = (type_data *)arg;
dt->ans = ;
if(dt->t == )
dt->ans = ;
for(int i = ; i < dt->t && i < dt->n; ){
if(i + dt->a[i] == dt->t)
dt->ans = ;
i += dt->a[i];
}
if(dt->ans == )
dt->ans = ;
}
int main(){
type_data* dt = (type_data *)winit();
io(dt);
wfinish(dt);
return ;
}
New Year Transportation(水)的更多相关文章
- hdu 4940 Destroy Transportation system(水过)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4940 Destroy Transportation system Time Limit: 2000/1 ...
- 【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s repr ...
- zoj3231 Apple Transportation(最大流)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Apple Transportation Time Limit: 1 Second ...
- POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Description Background Hugo ...
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Openjudge 1.13-21:最大质因子序列(每日两水)
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
随机推荐
- 在线C语言编译器/解释器
在线C语言编译器/解释器 本文介绍两个C语言在线解释器/编译器,这些工具可以提高代码片段检测方便的工作效率,并可以保证这些代码的正确性,而且还可以和别人一起编辑/分享之间的代码,这样可以共同分析代码并 ...
- poj 2388 Who's in the Middle
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31149 Accepted: 1 ...
- IE常见的CSS的BUG(一)
2011年6月,我毕业了.2012年我接触了CSS,本以为会好过些能赚点钱了,可谁知,Internet Explorer(下称IE),这个前端工程师的噩梦浏览器让我不再那么好过了.各种出现在IE身上的 ...
- Ubuntu 10.04下安装Qt
sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos qt4-designer qt-creator 其中: qt4-de ...
- 常用aliyun公共资源列表
公共DNS 223.5.5.5 223.6.6.6 源软件镜像站点 mirros.aliyun.com NTP服务器 unix like ntp1-7. ...
- NFinal学习笔记(一)
NFinal框架,最快的netWeb框架,其有三大特色,NFinalServer,NFinalBuild,NFinal代码生成器(生成web层) 首先学习了NFinalServer. NFinalSe ...
- WndPric的使用方法
protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOS ...
- 严重: Exception starting filter struts2 --Unable to load configuration
严重: Exception starting filter struts2 Unable to load configuration. - [unknown location] at com.open ...
- [OC笔记] static 关键字
在变量声明前加上static关键字,可以使局部变量保留多次方法调用所得到的值.当多个方法对一个静态变量进行操作时,多个方法共享同一个静态变量的值.
- 从字节理解Unicode(UTF8/UTF16)
如果你不知道或者不了解什么是Unicode/UTF8/UTF16,请详细阅读这篇文章(这也是这篇博文的先决条件): 学点编码知识又不会死:Unicode的流言终结者和编码大揭秘 但是如果你看完以上文章 ...