Easy Problem(cdOJ1644)

#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<stack>
#include<math.h>
#include<stdlib.h>

using namespace std;

struct my
{
    int left;
    int right;
}stir[1000];

int main()
{
    int i,j,k;
    char go[100][100];
    int num=0;
    int t;
    int n,m;
    cin>>t;
    while (t--)
    {
        num++;
        cin>>n>>m;
        for (i=0;i<n;i++)
            cin>>go[i];
        int l,r;
        stir[0].left=stir[0].right=-1;
        for (i=0;i<n;i++)
        {
            l=r=0;
            bool L=false;
            for (j=1;j<m-1;j++)
            {
                if (!L&&go[i][j]=='*')
                    L=true,l=j;
                if (go[i][j]=='*')
                    r=j;
            }
            if (l==0&&r==0)
                stir[i+1].left=stir[i].left+1,stir[i+1].right=stir[i].right+1;
            else
            {
                stir[i+1].left=min(stir[i].left+2*r,stir[i].right+m-1)+1;
                stir[i+1].right=min(stir[i].left+m-1,stir[i].right+2*(m-1-l))+1;
            }
                
        }
        if (m<3)
            cout<<"Case #"<<num<<": "<<n-1<<endl;
        else
        cout<<"Case #"<<num<<": "<<min(stir[n].left,stir[n].right)<<endl;
    }

}



Easy Problem

Time Limit: 1000 ms Memory Limit: 65536 kB Solved:122 Tried: 554

Description

Many students won prizes in UESTC Annual Amateur Contest last year. Yangsir asked Loveqinqin to send prizes to the winners' dormitories. Poor Loveqinqin found that these dormitories were scattered on several different floors of the dorm building.

Loveqinqin drew the map of the dorm building as showed in the following picture. Rooms colored red contained winners. Loveqinqin can only go to upstairs throught the stairs at either end of each floor.

Assume that it takes Loveqinqin one minute to walk from a room to a neighbour room. Going through the stairs from Floor i to Floor i + 1 also takes one minute. Note that if a room is near to the stairs, the time Loveqinqin needs to walk between stairs and that room is one minute.

Loveqinqin could start at either end of the Floor 1 and would stop at either end of the topmost floor. Please find a route which takes the minimum minutes, through which Loveqinqin can send prizes to all winners.

Input

There are multiple test cases. The first line of the input will be an integer T (T <= 100) indicating the number of test cases.

For each test case, in the first line there are two numbers: N M, indicating the number of floors (1 <= N <= 100) and the width of each floor (1 <= M <= 100). The following N lines describe the distribution of the winners. The first line is about Floor 1, the second line is about Floor 2, ..., the last line is about Floor N.

We use '*' to denote a room containing winners, '.' to denote other rooms, 's' to denote stairs. We guarantee that the width of each floor equals M. The two ends of each lines are the only places where 's' appears.

Output

For each test case, print "Case #t: " first, in which t is the number of the test case starting from 1. Then output the minimum minutes.

Simple Input

4
1 4
s*.s
3 3
s.s
s*s
s.s
4 4
s*.s
s.*s
s..s
s*.s
4 6
s*...s
s..**s
s.*..s
s..*.s

Simple Output

Case #1: 2
Case #2: 4
Case #3: 11
Case #4: 20

Hint

In the first case, Loveqinqin has to return to one of the ends of the first floor.
This is really an easy problem. Come on!!!

Source

10th UESTC Programming Contest Preliminary





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值