VK Cup 2016 - Qualification Round 1 - D. Running with Obstacles

题意 :

在 x 坐标轴上,从 0 到 m 点,中途有 n 个障碍,遇到障碍可以 跳,
但是每次跳之前需要一段 距离为 s 的“助跑 ”,而且每次跳跃距离不能超过 d ,不能落在障碍点上;
给出 n,m,s,d,接下来 n 个数 ,表示障碍的坐标。
输入保证起点和终点不会有障碍,不会有两个障碍在同一位置。
输出到达终点的过程。如果不能到达终点输出“IMPOSSIBLE” 。

解题:

模拟啊模拟(好烦好烦= =)

首先 他一定是跑到距离障碍最近的位置才跳的,这样可以跳的更远些。
然后两个障碍之间相距 要大于等于 s+2 ,才可以再次跳,否则不能到达终点了。
所以只要在 d 范围里找到了这样 一段距离(只要起始位置包含在 d 里就可以辣) 就继续往前跳。
为了方便把数组的 n+1 位 设置成 a[n+1] = m+1;
这样判断的时候如果 到了最后的位置就不判断直接跳过去。

感觉智商被掏空 乱七八糟不知道说了啥 = =直接代码好懂

吐槽 :
WOC! 写了一天...
好不容易算法对了,算错范围 WA 的不知所措 = = 真的是找了好久
好菜啊啊啊 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#define ll __int64
using namespace std;
const int maxn = 200010;
ll a[maxn],ans[maxn];
int main()
{
    int n,m,s,d;
    scanf("%d%d%d%d",&n,&m,&s,&d);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+n+1);
    a[n+1] = m+1;
    ll pos = a[1] - 1, las = 0;
    int cnt = 0, f = 0;
    ans[cnt++] = pos - las;
    for(int i=1;i<=n;i++) {
        if(pos - las >= s) { //如果满足跳的条件
            int j, fg = 0;
            for(j = i+1; j<=n+1 ; j++) {
                if( a[i]-pos >= d) break;  // d范围内寻找
                if( ( (a[j]-1) - (a[i]+1) >= s) || (j==n+1) ){
                    fg = 1; break;
                }
                i ++ ;
            }
            if(!fg) {
                 f = 1; break;
            }
            las = a[i] + 1;
            ans[cnt++] = las - pos;
            pos = a[j] - 1;
            ans[cnt++] = pos - las;
        }
        else {
            f = 1; break;
        }
    }
    if(f) printf("IMPOSSIBLE\n");
    else {
        for(int i=0;i<cnt;i++) {
            if(ans[i])
                printf((i%2)?"JUMP %I64d\n":"RUN %I64d\n",ans[i]);
        }
    }
    return 0;
}
时间: 2024-08-04 23:34:32

VK Cup 2016 - Qualification Round 1 - D. Running with Obstacles的相关文章

DP VK Cup 2012 Qualification Round D. Palindrome pairs

题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 1 /* 2 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 3 DP:很巧妙的从i出发向两头扩展判断是否相同来找回文串 4 dpr[i] 代表记录从0到i间的回文子串的个数,dpl[i] 代表记录i之后的回文子串个数 5 两两相乘就行了 6 详细解释:http://blog.csdn.net/shiyuankongbu/article/details

VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟

C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Description One popular website developed an unusual username editing procedure. One can change the username only by deleting some characte

VK Cup 2012 Qualification Round 1 C. Cd and pwd commands 模拟

C. Cd and pwd commands Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/158/C Description Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he dec

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

A. Bear and Game 题意:一个体育节目,它可能在某一分钟是很有趣的,其他时间都是很无聊的,如果持续十五分钟都很无聊的话那么Bear就会关掉电视,问什么时候会关掉电视. 题解:用第i个有趣的时间减去第i-1个有趣的时间,如果差值大于十五分钟那就输出第i个有趣的时间+15.注意第一个有趣的时间要为0,最后一个为90. 代码: 1 /*A*/ 2 #include<cstdio> 3 using namespace std; 4 5 const int maxn=95; 6 7 int

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B

#include<stdio.h> #include<algorithm> #include<vector> #include<string.h> using namespace std; int main() { int n,m,i; while(scanf("%d%d",&n,&m)!=EOF) { vector<int> da,xi; int a,b; int maxa=1,minb=n; for(i=1

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

C. Little Artem and Random Variable Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Consider two dices. When thrown each dice shows some integer from 1 to

Codeforces Round #348(VK Cup 2016 - Round 2)

A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int n; scanf ("%d", &n); int ans = n / 3 * 2; if (n % 3) { ans++; } printf ("%d\n", ans);

codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + m > 0) ps:很水的题,主要是策略: 思路:由于里面每隔6就会重复一次,不好直接模拟,并且模拟的效率很低,那就二分吧!二分即上界为2单独的最大倍数与3单独时的最大倍数之和,下界为前面二者的max;之后利用判断是否mid/2 >= n && mid/3 >= m &am

8VC Venture Cup 2016 - Elimination Round

在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, int &y, char ch) { if (ch == 'U') x--; if (ch == 'D') x++; if (ch == 'L') y--; if (ch == 'R') y++; } int main(void) { int n; scanf ("%d", &