Help on SPOJ problems
时间:2013-05-30
来源:互联网
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
引用:
原帖由 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
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
首先根据条件的话
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
引用:
原帖由 fitcat07 於 2013-5-30 20:32 发表系其中一个可能出现嘅答案。
睇睇输出例子,第4个就系要咁样答。
作者: a8d7e8 发布时间: 2013-05-30
引用:
原帖由 a8d7e8 於 2013-5-30 08:43 PM 发表between 即系 exclusively 定 inclusively???
作者: 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 ...
跑到一个空格就check "of "...
跑到结尾都只是一个空格就是Not sure
但如果跑到第二个check "of "都不是Magic就是Normal
作者: cheng_chai_fung 发布时间: 2013-05-30
代码:
#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
作者: a8d7e8 发布时间: 2013-05-30
引用:
原帖由 a8d7e8 於 2013-5-30 11:18 PM 发表Damaged's sword -> Not sure?
因为Somebody's Something of Whatever也是Set
应该Set是绝对的
作者: cheng_chai_fung 发布时间: 2013-05-30
作者: a8d7e8 发布时间: 2013-05-30
引用:
原帖由 a8d7e8 於 2013-5-30 11:27 PM 发表Jordan's -> Set?
======================
结果还是不知道...改了也都WA
[ 本帖最后由 cheng_chai_fung 於 2013-5-30 11:39 PM 编辑 ]
作者: cheng_chai_fung 发布时间: 2013-05-30
Albert''s sword -> Normal?
作者: a8d7e8 发布时间: 2013-05-30
引用:
原帖由 a8d7e8 於 2013-5-30 11:45 PM 发表How about this?
Albert''s sword -> Normal?
作者: cheng_chai_fung 发布时间: 2013-05-31
代码:
#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-05-31
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
====================================
喔...我忘掉了...还有开头的空格...
====================================
http://ideone.com/UESi5Z
WA
[ 本帖最后由 cheng_chai_fung 於 2013-5-31 12:57 AM 编辑 ]
作者: cheng_chai_fung 发布时间: 2013-05-31
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!
如果出现呢D野我会o晒lor
作者: cheng_chai_fung 发布时间: 2013-05-31
如果系跟足 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 都应 ...
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
http://i.imgur.com/6QtfYB9.png <-- 18+的...衣服的迟下会画...orz
=============================
还是先睡觉了~
[ 本帖最后由 cheng_chai_fung 於 2013-5-31 02:50 AM 编辑 ]
作者: cheng_chai_fung 发布时间: 2013-05-31
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28