首页 > 代码库 > hdu 2725

hdu 2725

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2725

题意:给一个字符串表示一条河。‘.‘表示水,其它字符表示障碍。人在岸上用石子打水漂,每次可以选择一个击中的距离和跳跃间隔。石子多次跳跃后击中障碍物或越过河则结束。每种打水漂的方案按跳跃次数(大者优)、最后在河中的距离(大者优)、起始位置(大者优)、跳跃间隔(小者优)比较,问最好的方案是哪种。

mark:无坑。直接写就好。

#include <stdio.h>#include <string.h>int count, length;int rcount, rlength, ri, rj;int len;char str[100];int calc(int pos, int skip){    count = 0, length = pos;    while (pos < len && str[pos] == .)    {        pos += skip, count++;        if (pos < len) length = pos;    }}void update (int c, int l, int p, int k){    if (c < rcount) return ;    if (c > rcount){        rcount = c, rlength = l, ri = p, rj = k;        return ;    }    if (l < rlength) return ;    if (l > rlength){        rcount = c, rlength = l, ri = p, rj = k;        return ;    }    if (p < ri) return ;    if (p > ri){        rcount = c, rlength = l, ri = p, rj = k;        return ;    }    if (k > rj) return;    rcount = c, rlength = l, ri = p, rj = k;}int main(){    int i, j;    while (~scanf ("%s", str) &&strcmp(str, "END"))    {        rcount = rlength = ri = -1;        rj = 0x0fffffff;        len = strlen(str);        for (i = 0; i < len; i++)            for (j = 1; i + j <= len; j++)            {                calc(i, j);                update(count, length, i, j);            }        printf ("%d %d\n", ri, rj);    }    return 0;}

 

hdu 2725