您的位置:首页 > 其它

[uva1588]Kickdown

2016-03-14 20:20 316 查看

注意事项

1.一定要注意分析的方法,不要陷入列举有什么符合,而尽量先考虑什么不行,排除就好。
2.三个错误点
1.上下不一定是上长下短。
2.可以在板子里面也可以有一部分到外面
3.可以向左伸,也可以向右伸。


心得体会

一定要反向思维,看看什么不行。直接列举实在太难想全。

渣渣代码

#include <stdio.h>
#include <string.h>
char topLineT[1000], bottomLineT[1000];
void check(void);
int main(void)
{
while (gets(bottomLineT))
{
gets(topLineT);
check();
}
return 0;
}
void check(void)
{
int lenTop = strlen(topLineT), lenBottom = strlen(bottomLineT);
char topLine[1000], bottomLine[1000];
if (lenTop > lenBottom)
{
strcpy(topLine, bottomLineT);
strcpy(bottomLine, topLineT);
int temp = lenTop;
lenTop = lenBottom;
lenBottom = temp;
}
else
{
strcpy(topLine, topLineT);
strcpy(bottomLine, bottomLineT);
}

//不伸出去
for (int count1 = 0; count1 <= lenBottom - lenTop; count1++)
{
for (int count2 = 0; count2 <= lenTop; count2++)
{
if (bottomLine[count1 + count2] + topLine[count2] >= 2 * '2')
{
break;
}
if (count2 == lenTop)
{
printf("%d\n", lenBottom);
return;
}
}
}
//伸出去
for (int count1 = 1; count1 < lenTop; count1++)
{
for (int count2 = 0; count2 + count1 <= lenTop; count2++)
{
if (topLine[count1 + count2] + bottomLine[count2] >= 2 * '2')
{
break;
}
if (count2 + count1 == lenTop)
{
printf("%d\n", count1 + lenBottom);
return;
}
}
for (int count2 = 0; count1 + count2 <= lenTop; count2++)
{
if (topLine[lenTop - count1 - count2] + bottomLine[lenBottom - count2] >= 2 * '2')
{
break;
}
if (count1 + count2 == lenTop)
{
printf("%d\n", count1 + lenBottom);
return;
}
}
}
printf("%d\n", lenBottom + lenTop);
return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva