[Offer收割]编程练习赛24 register

Ended

Participants:356

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-27 14:00:21

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <vector>
#include <iostream>
using namespace std;
int jump(vector<int>& arr, int start) {
    int cnt = 0;
    while (start < arr.size()) {
        ++cnt;
        start += arr[start];
    }
    return cnt;
}
int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    int q;
    cin >> q;
    for (int i= 0; i < q; ++i) {
        int x;
        cin >> x;
        if (x == 1) {
            int y;
            cin >> y;
            cout << jump(arr, y - 1) << endl;
        } else {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX