+ -
当前位置:首页 → 问答吧 → Help on SPOJ problems

Help on SPOJ problems

时间:2013-05-30

来源:互联网

Any one can help on the following 2 problems:

http://www.spoj.com/problems/UOFTBD/
http://www.spoj.com/problems/DCOWS/

The first one seems to be very easy. However, I got a lot of WA (wrong answer).
Currently, only 2 people can get AC (accepted).

I tried the 2nd one with greedy (WA), recursive with memorization (TLE) and
dynamic programming (WA). Any hints?

作者: fitcat07   发布时间: 2013-05-30

Funny but looks hard.
引用:
原帖由 fitcat07 於 2013-5-30 14:22 发表
Any one can help on the following 2 problems:

http://www.spoj.com/problems/UOFTBD/
http://www.spoj.com/problems/DCOWS/

The first one seems to be very easy. However, I got a lot of WA (wrong ans ...

作者: a8d7e8   发布时间: 2013-05-30

UOFTBD那个不太明...
Not sure, take anyways是其中一个正确答案...???还是计分...???

============================
还有...Rare items always have names that are two words long.
Magic items在3~4字时就会有of [something]
但2字的Magic items...不就是跟Rare items完全一样了吗...???
那么
Rare items就完全没可能分别出来...只会一直的Not sure.???

[ 本帖最后由 cheng_chai_fung 於 2013-5-30 08:31 PM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-30

系其中一个可能出现嘅答案。
睇睇输出例子,第4个就系要咁样答。

作者: fitcat07   发布时间: 2013-05-30

UOFTBD
首先根据条件的话
1. check头7个字元是否"Damaged" -> Normal
2. search第一个空格的位置...check前两字元是否"'s" -> Set
3. 统计空格数目...
4. 空格数目 == 1 -> Not sure
5. 空格数目 == 2的话, check第一个空格之后的位置是否"of " (连空格check) -> Magic
6. 空格数目 == 3的话, check第二个空格之后的位置是否"of " (连空格check) -> Magic
7. 都不是的话 -> Normal

Rare不会是答案

[ 本帖最后由 cheng_chai_fung 於 2013-5-30 08:43 PM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-30

between 即系 exclusively 定 inclusively???
引用:
原帖由 fitcat07 於 2013-5-30 20:32 发表
系其中一个可能出现嘅答案。
睇睇输出例子,第4个就系要咁样答。

作者: a8d7e8   发布时间: 2013-05-30

引用:
原帖由 a8d7e8 於 2013-5-30 08:43 PM 发表
between 即系 exclusively 定 inclusively???

stone of jordan->Magic

作者: cheng_chai_fung   发布时间: 2013-05-30

引用:
原帖由 cheng_chai_fung 於 2013-5-30 08:42 PM 发表
UOFTBD
首先根据条件的话
1. check头7个字元是否"Damaged" -> Normal
2. search第一个空格的位置...check前两字元是否"'s" -> Set
3. 统计空格数目...
4. 空格数目 == 1 -> Not sure
5. 空格数目 == 2的话, ch ...
或者...针对空格...用loop一直的跑下去...第三个统计空格数目也不用去做
跑到一个空格就check "of "...
跑到结尾都只是一个空格就是Not sure
但如果跑到第二个check "of "都不是Magic就是Normal

作者: cheng_chai_fung   发布时间: 2013-05-30

未有时间整理...只是按想法交了一次...然后WA
复制内容到剪贴板
代码:
#include <iostream>
#include <string>
#include <cctype>

#define of(str, i) ((str[i + 1] == 'o' || str[i + 1] == 'O') \
&& (str[i + 2] == 'f' || str[i + 2] == 'F') && str[i + 3] == ' ')

int main()
{
    int n;
    std::cin >> n;
    std::string str;
    std::getline(std::cin, str);
   
    for(int i = 0; i < n; ++i)
    {
        std::getline(std::cin, str);
        for(int j = 0; j < 7; ++j)
            str[j] = tolower(str[j]);
        if(str.substr(0, 8) == "damaged ")
        {
            std::cout << "Normal\n";
            continue;
        }
        
        int idx = str.find_first_of(' ');
        if(str[idx - 2] == '\'' && (str[idx - 1] == 's' || str[idx - 1] == 'S'))
        {
             std::cout << "Set\n";
             continue;
        }
            
        if(idx == std::string::npos)
        {
            std::cout << "Normal\n";
            continue;
        }
        if(of(str, idx))
        {
            if(str.find_first_of(' ', idx + 4) == std::string::npos)
            {
                std::cout << "Magic\n";
                continue;
            }
        }
        idx = str.find_first_of(' ', idx + 1);
        if(idx == std::string::npos)
        {
            std::cout << "Not sure, take anyways\n";
            continue;
        }
        if(of(str, idx))
        {
            if(str.find_first_of(' ', idx + 4) == std::string::npos)
            {
                std::cout << "Magic\n";
                continue;
            }
        }
        std::cout << "Normal\n";
    }
   
    return 0;
}

作者: cheng_chai_fung   发布时间: 2013-05-30

Damaged's sword -> Not sure?

作者: a8d7e8   发布时间: 2013-05-30

引用:
原帖由 a8d7e8 於 2013-5-30 11:18 PM 发表
Damaged's sword -> Not sure?
Set
因为Somebody's Something of Whatever也是Set
应该Set是绝对的

作者: cheng_chai_fung   发布时间: 2013-05-30

Jordan's -> Set?

作者: a8d7e8   发布时间: 2013-05-30

引用:
原帖由 a8d7e8 於 2013-5-30 11:27 PM 发表
Jordan's -> Set?
单字吗..???这个我没有考虑过...但这会是Set..吗???
======================
结果还是不知道...改了也都WA

[ 本帖最后由 cheng_chai_fung 於 2013-5-30 11:39 PM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-30

How about this?

Albert''s sword -> Normal?

作者: a8d7e8   发布时间: 2013-05-30

引用:
原帖由 a8d7e8 於 2013-5-30 11:45 PM 发表
How about this?

Albert''s sword -> Normal?
会有 '' 的吗...???不过不是说they always begin with a word that ends in "'s". No other items are special enough to begin this way.

作者: cheng_chai_fung   发布时间: 2013-05-31

排除了double space char的可能....WA
复制内容到剪贴板
代码:
#include <iostream>
#include <string>
#include <cctype>

#define ss(str, i) (str[i - 2] == '\'' && (str[i - 1] == 's' || str[i - 1] == 'S'))
#define of(str, i) ((str[i + 1] == 'o' || str[i + 1] == 'O') \
&& (str[i + 2] == 'f' || str[i + 2] == 'F') && str[i + 3] == ' ')

int main()
{
    int n;
    std::cin >> n;
    std::string str;
    std::getline(std::cin, str);
   
    for(int i = 0; i < n; ++i)
    {
        std::getline(std::cin, str);
        while(str.find_last_of(' ') == str.length() - 1)
            str.erase(str.length() - 1, 1);
        for(int j = 0; j < 7; ++j)
            str[j] = tolower(str[j]);
        if(str.substr(0, 8) == "damaged ")
        {
            std::cout << "Normal\n";
            continue;
        }
        
        int idx = str.find_first_of(' ');
        int offset = 1;
        while(str.find_first_of(' ', idx + offset) - idx == offset)
             ++offset;
        if(ss(str, idx))
        {
             std::cout << "Set\n";
             continue;
        }
            
        if(idx == std::string::npos)
        {
            if(ss(str, str.length()))
                std::cout << "Set\n";
            else
                std::cout << "Normal\n";
            continue;
        }
        if(of(str, idx + offset - 1))
        {
            idx += 3;
            while(str.find_first_of(' ', idx + offset) - idx == offset)
                ++offset;
            if(str.find_first_of(' ', idx + offset) == std::string::npos)
            {
                std::cout << "Magic\n";
                continue;
            }
        }
        idx = str.find_first_of(' ', idx + offset);
        offset = 1;
        while(str.find_first_of(' ', idx + offset) - idx == offset)
             ++offset;
        if(idx == std::string::npos)
        {
            std::cout << "Not sure, take anyways\n";
            continue;
        }
        if(of(str, idx + offset - 1))
        {
            idx += 3;
            while(str.find_first_of(' ', idx + offset) - idx == offset)
                ++offset;
            if(str.find_first_of(' ', idx + offset) == std::string::npos)
            {
                std::cout << "Magic\n";
                continue;
            }
        }
        std::cout << "Normal\n";
    }
   
    return 0;
}
[ 本帖最后由 cheng_chai_fung 於 2013-5-31 12:34 AM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-31

呢啲  case.....

Jodarn's
Jordan''s sword
's sword
's

作者: a8d7e8   发布时间: 2013-05-31

引用:
原帖由 a8d7e8 於 2013-5-31 12:49 AM 发表
呢啲  case.....

Jodarn's
Jordan''s sword
's sword
's
正常的全部出了Set 0.0
====================================
喔...我忘掉了...还有开头的空格...
====================================
http://ideone.com/UESi5Z
WA

[ 本帖最后由 cheng_chai_fung 於 2013-5-31 12:57 AM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-31

我觉得 's 呢啲唔 make sense 的 input 唔应该当系 set.

Normal 又不像 normal, not sure, take anyways!

作者: a8d7e8   发布时间: 2013-05-31

引用:
原帖由 a8d7e8 於 2013-5-31 01:49 AM 发表
我觉得 's 呢啲唔 make sense 的 input 唔应该当系 set.

Normal 又不像 normal, not sure, take anyways!
唔 make sense 大概唔会出现吧....条问题的背景是Diablo的物品分类programme
如果出现呢D野我会o晒lor

作者: cheng_chai_fung   发布时间: 2013-05-31

查实按 rule "'s" 唔应该属於 Set. 因为 set "always begin with a word" and "a "word" is a maximal substring of non-space characters".

如果系跟足 rules 唔理有无可能有呢啲 inputs 你个 program 都应该要 handle 得啱喎.

佢要试你做唔做足就自然会用 special case test........

作者: a8d7e8   发布时间: 2013-05-31

引用:
原帖由 a8d7e8 於 2013-5-31 01:55 AM 发表
查实按 rule "'s" 唔应该属於 Set. 因为 set "always begin with a word" and "a "word" is a maximal substring of non-space characters".

如果系跟足 rules 唔理有无可能有呢啲 inputs 你个 program 都应 ...
但跟足rule的话
Set items always belong to some famous dead person, so they always begin with a word that ends in "'s".
"'s"也是a word ends in "'s"

作者: cheng_chai_fung   发布时间: 2013-05-31

啊...一边在画这张图一般玩SPOJ XD

http://i.imgur.com/6QtfYB9.png <-- 18+的...衣服的迟下会画...orz

=============================
还是先睡觉了~

[ 本帖最后由 cheng_chai_fung 於 2013-5-31 02:50 AM 编辑 ]

作者: cheng_chai_fung   发布时间: 2013-05-31

热门下载

更多