zoukankan      html  css  js  c++  java
  • POJ 3672 Long Distance Racing (模拟)

    题意:给定一串字符,u表示是上坡,d表示下坡,f表示平坦的,每个有不同的花费时间,问你从开始走,最远能走到。

    析:直接模拟就好了,没什么可说的,就是记下时间时要记双倍的,因为要返回来的。

    代码如下:

    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int maxn = 1000 + 5;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int m, n;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int main(){
        int t, u, f, d;
        while(scanf("%d %d %d %d %d", &m, &t, &u, &f, &d) == 5){
            int ans = 0;
            char s[5];
            LL cnt = 0;
            for(int i = 0; i < t; ++i){
                scanf("%s", s);
                if(s[0] == 'u' || s[0] == 'd')  cnt += u + d;
                else if(s[0] == 'f')  cnt += f + f;
                if(cnt <= m)  ++ans;
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    Java NIO使用及原理分析(二)(转)
    Java NIO使用及原理分析 (一)(转)
    虚拟机字节码执行引擎
    虚拟机类加载机制
    浅析Java中的final关键字
    java内存模型7-处理器内存模型
    java内存模型6-final
    最小生成树
    有向图的基本算法
    并查集(Union-Find)算法介绍
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5754369.html
Copyright © 2011-2022 走看看