URAL 1525 Path

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;
char s[maxn];
int main()
{
    long long int n, m, k;
    while (~scanf("%lld%lld%lld", &n, &m, &k))
    {
        scanf("%s", s);
        int y = strlen(s);
        int i;
        long long int sum1 = 0, sum2 = 0, sum3 = 0;
        long long int maxn1 = 0, maxn2 = 0, maxn3 = 0, minn1 = 0, minn2 = 0, minn3 = 0;
        for (i = 0; i < y; i++)
        {
            if (s[i] == ‘u‘)
            {
                sum1++;
                if (sum1 >= maxn1) maxn1 = sum1;

            }
            else if (s[i] == ‘d‘)
            {
                sum1--;
                if (sum1 <= minn1) minn1 = sum1;

            }

            else if (s[i] == ‘l‘)
            {
                sum2++;
                if (sum2 >= maxn2) maxn2 = sum2;

            }
            else if (s[i] == ‘r‘)
            {
                sum2--;
                if (sum2 <= minn2) minn2 = sum2;

            }

            else if (s[i] == ‘f‘)
            {
                sum3++;
                if (sum3 >= maxn3) maxn3 = sum3;

            }
            else if (s[i] == ‘b‘)
            {
                sum3--;
                if (sum3 <= minn3) minn3 = sum3;

            }
        }
        long long int k1, k2, k3, ans;
        if (m - maxn1 + minn1 <= 1) m = 1;
        else m = m - maxn1 + minn1;
        if (n - maxn2 + minn2 <= 1) n = 1;
        else n = n - maxn2 + minn2;
        if (k - maxn3+ minn3 <= 1) k = 1;
        else k = k - maxn3 + minn3;
        printf("%lld\n", n*m*k);
    }
    return 0;
}
时间: 2024-11-05 10:54:11

URAL 1525 Path的相关文章

ural 1143. Electric Path(凸包上最短哈密顿路径)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1143 题意:逆时针给一个凸包的n(n<=200)个顶点坐标,求一个最短哈密顿路径的长度. 解法:求最短哈密顿本身是一个NP问题,但是因为是凸包上,可以利用这个做:有一个性质:凸包上的最短哈密顿路径不会出现交叉.所以可以看出来从一点出发,他要么和顺时针相邻点连接,要么和逆时针相邻点相连接:通过这个性质可以通过dp做: ans[i][j][0]表示i开始,往后j的点最短路径长度,ans[i][

ural 1143. Electric Path

1143. Electric Path Time limit: 1.0 secondMemory limit: 64 MB Background At the team competition of the 10th national student informatics Olympic, which is organized at Hanoi National University, there are N teams participating. Each team is assigned

URAL 2005. Taxi for Programmers (最短路 数学啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2005 2005. Taxi for Programmers Time limit: 0.5 second Memory limit: 64 MB The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have just finished their trai

ural 2030

Awesome Backup System Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 2030 Description It is known that all people can be divided into two groups: those who have never lost important data and t

URAL 1932 The Secret of Identifier 题解

http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1932 Description Davy Jones: You've been captain of the Black Pearl for

URAL 1934 spfa算法

D - Black Spot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1934 Description Bootstrap: Jones's terrible leviathan will find you and drag the Pearl back to the depths and you along with it.

Linux下修改环境变量PATH

1.什么是环境变量(PATH) 在Linux中,在执行命令时,系统会按照PATH的设置,去每个PATH定义的路径下搜索执行文件,先搜索到的文件先执行. 我们知道查阅文件属性的指令ls 完整文件名为:/bin/ls(这是绝对路径), 那你会不会觉得很奇怪:"为什么我可以在任何地方执行/bin/ls这个指令呢? " 为什么我在任何目录下输入 ls 就一定可以显示出一些讯息而不会说找不到该 /bin/ls 指令呢? 这是因为环境变量 PATH 的帮助所致呀! 当我们在执行一个指令癿时候,举例

Description Resource Path Location Type The superclass &quot;javax.servlet.http.HttpServlet&quot; was not foun

一段时间没亲自建新项目玩乐,今天建立了一Maven project的时候发现了以下异常,Description Resource Path Location Type The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path index.jsp /easyBuy/src/main/webapp line 1 JSP Problem 经过查找原因,原来是因为忘记设置server

Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]56528192: startup date [Tue Sep 19 15:05:24 CST 2017]; root of context hierarchy 2017-09-19 15:05:24.858 INFO 9986 --