每周编程题 (19/4 - 25/4)
时间:2014-05-18
来源:互联网

搵到一题好浅(如果你明白条题目):
http://www.spoj.com/problems/KIT/
我就睇唔明,系有人喺 SPOJ 论坛讲解先知道想点。
估就估到,但斋睇题目真系唔知讲乜,可能系我英文水皮。

请大家唔好睇评论同论坛相关帖子,睇下明唔明。
另外,想请教以下呢题:http://www.spoj.com/problems/INS14D/
遇到困难,请试试睇以下教学网页:http://www.topcoder.com/tc?d1=tutorials&d2=alg_index&module=Static
亦欢迎发问。
常用 SPOJ 题术语解释:
AC - 代表 Accepted,表示答案符合要求,已被接受。
WA - 代表 Wrong Answer,表示答案出错。
TLE - 代表 Time Limited Exceeded,表示超出时间限制。
作者: fitcat07 发布时间: 2014-05-18
只系做维吉尼亚密码...或者移位式密码
即系
10
1 2 3 4 5 4 3 2 1 0
aa aaa
zzzzz
-1
Output 1:
bc
def
dcbaz
然后使用密码加密
即
'a' + 2 = 'c'
'a' + 3 = 'd'
'a' + 4 = 'e'
'a' + 5 = 'f'
'z' + 4 = 'd'
'z' + 3 = 'c'
'z' + 2 = 'b'
'z' + 1 = 'a'
'z' + 0 = 'z'
作者: Susan﹏汪汪 发布时间: 2014-05-18
#include <string>
using namespace std;
int main() {
// your code goes here
int n = 0;
cin >> n;
int *pad = new int[n];
for(int i = 0; i < n; ++i)
{
cin >> pad[i];
}
int shift = 0;
char chr;
bool jump = true;
while(cin.get(chr))
{
if(chr == '-')
{
cin >> chr;
if(chr == '1')
{
break;
}
}
if(chr < 'a' || chr > 'z')
{
if(!jump) cout << endl;
jump = true;
continue;
}
jump = false;
char temp = (((chr - 'a') + pad[shift++]) % 26) + 'a';
shift %= n;
cout << temp;
}
delete[] pad;
return 0;
}
作者: Susan﹏汪汪 发布时间: 2014-05-18

我读到呢句,畀佢混乱咗我:
重有,我睇过不下五次,都睇唔到有话顺序由第一个 number-pad 嘅数字开始,直到尾,然后返回第一个数字。
都系嗰句,估就估到,理解不能。唯有承认英文差...

作者: fitcat07 发布时间: 2014-05-18
做得好!

我读到呢句,畀佢混乱咗我:
呢句话「can be ... if ...」,即系话情况许可,就做到加密。咁情况唔许可呢?冇讲到喎。
重有,我睇过不下五次,都睇唔到有话顺序由第一个 number-p ...
作者: Susan﹏汪汪 发布时间: 2014-05-18
汪汪随便写左个...居然用左好多时间去跑三个test...然后TLE
但如果佢冇一开始就拋出WA...即系话答案应该啱
using namespace std;
int main() {
// your code goes here
uint32_t n, t;
cin >> n;
for(uint32_t i = 0; i < n; ++i)
{
cin >> t;
cout << (t / 5 + (t % 5 ? 1 : 0)) << endl;
}
return 0;
}
作者: Susan﹏汪汪 发布时间: 2014-05-18
作者: Susan﹏汪汪 发布时间: 2014-05-18
果句只系英文写法问题...无咩特别意思
作者: fitcat07 发布时间: 2014-05-18
第三个test终於攞到WA
原来自己搞错咗一尐嘢,现在已经 AC

作者: fitcat07 发布时间: 2014-05-18
数据量太多,用 cin 会比 scanf 慢得多,因此 TLE。
原来自己搞错咗一尐嘢,现在已经 AC

应该有special case
作者: Susan﹏汪汪 发布时间: 2014-05-18
攞到WA
应该有special case
唔想剧透,我将文字反白了。

作者: fitcat07 发布时间: 2014-05-18
第二题...Digo Needs Guns
汪汪随便写左个...居然用左好多时间去跑三个test...然后TLE
但如果佢冇一开始就拋出WA...即系话答案应该啱#include
using namespace std;
int main() {
// your code g ...
(9 / 5 + (9 % 5 ? 1 : 0)) = 1

作者: assembly.jc 发布时间: 2014-05-18
作者: form5 发布时间: 2014-05-18
Hi susan,就这么简单,以下这个九边形,需要 4 伎 gun? 但
(9 / 5 + (9 % 5 ? 1 : 0)) = 1
https://lh4.googleusercontent.com/-riQpfdCxc3c/U1Kj-IbBm8I/AAAAAAAAAFs/zH-vDqaMRUk/w669-h437-no/ploygon.png
= 1 + (4 ? 1 : 0)
= 1 + 1
= 2
作者: Susan﹏汪汪 发布时间: 2014-05-18
I don't understand the second question, what is that gun for? how to get result 1? Anyone can explain that?
By means of "cover", any positions of the room can be reached by bullets from at least one gun.
Consider the example from assembly.jc:

There are nine intersections from all the nine walls, namely A - I.
If we only place only one gun at intersection A, its bullets can't reach areas near intersections C, D, E and F.
If we place a gun at A, B, C and D, the whole room can be covered.
But the question is, can we place less than 4 guns to do this?
What is the minimum number of guns required?
Remember, we don't know the shape of the room in advance - just the number of walls and the rooms are polygons.
作者: fitcat07 发布时间: 2014-05-18
9 / 5 + (9 % 5 ? 1 : 0)
= 1 + (4 ? 1 : 0)
= 1 + 1
= 2
哈, 唔好意思,计错算

13 / 5 + (13 % 5 ? 1 : 0) = 3

[ 本帖最后由 assembly.jc 於 2014-4-20 02:38 PM 编辑 ]
作者: assembly.jc 发布时间: 2014-05-18
Hi susan,
哈, 唔好意思,计错算

13 / 5 + (13 % 5 ? 1 : 0) = 3
https://lh5.googleusercontent.com/-864y7seIbuw/U1Nq3CGXMXI/AAAAAA ...
2014-4-20 04:59 PM
2014-4-20 04:59 PM
作者: Susan﹏汪汪 发布时间: 2014-05-18
This snake (9 wall) need 3 guns


作者: assembly.jc 发布时间: 2014-05-18
Hi susan,
This snake (9 wall) need 3 guns

https://lh3.googleusercontent.com/-Ia6TUDvZaSI/U1R1G-SJGDI/AAAAAAAAAG8/UEAAa9vME5c/w669-h437-no/ploygon3.png
作者: Susan﹏汪汪 发布时间: 2014-05-18
咁要改公式做n / 4 + (n % 4 ? 1 : 0)
No。It got WA
作者: assembly.jc 发布时间: 2014-05-18
作者: Susan﹏汪汪 发布时间: 2014-05-18
n / 5 + (n % 5) / 3 + (n % 5 % 3 ? 1 : 0)
let n = 4, it gives 2

作者: assembly.jc 发布时间: 2014-05-18
hi susan,
let n = 4, it gives 2


作者: Susan﹏汪汪 发布时间: 2014-05-18
好难

可能不是 linear 的关系 (做紧上星那题 (bloper),未有时间细想)。不过,画图画到九边形都是 linear。迟一下画多几个图,可能会清楚一些。
作者: assembly.jc 发布时间: 2014-05-18
好难

1. 用一支枪时,最大嘅 n 系多少?
2. 用两支枪时,最大嘅 n 系多少?
作者: fitcat07 发布时间: 2014-05-18
提示:
作者: Susan﹏汪汪 发布时间: 2014-05-18
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28