Codeforces New Year Transportation

来源:互联网 发布:app数据库设计实例 编辑:程序博客网 时间:2024/06/06 02:16


题目链接:http://codeforces.com/problemset/problem/500/A


import java.util.Scanner;public class NewYearTransportation {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();int t = scanner.nextInt();int[] a = new int[n];for(int i = 1; i < n; i++) {a[i] = i + scanner.nextInt();}int j = 1;while(j < n) {if(a[j] == t) {System.out.println("YES");return ;}j = a[j];}System.out.println("NO");}}


原创粉丝点击