这道题目很经典,很多书和OJ里都有。如果初次遇到,一定很难搞定。再看其解法,实在是很惊艳。
有两个可以得到深刻启示的地方:
(1)冗余的思想。谈到复制,我们往往都会另起炉灶,而不会原来链表上搞来搞去,感觉很复杂很危险,会一团糟。美错,最危险的地方就是最安全的地方。
(2)指针的步伐。这里的指针有一走两步的操作,很容易导致RE。但是否意味着每步都要仔细考虑指针越界?不然,那样程序会写的很累很乱...
分类:
其他好文 时间:
2014-12-05 12:50:51
阅读次数:
165
#include
#include
#include
#define N 10010
using namespace std;
int main()
{
int m,i,a[N],b[N],top,n,y,j;
string x[N];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>m;
top=0;
for(i=1;i<=m;...
分类:
其他好文 时间:
2014-12-05 00:50:43
阅读次数:
227
#include
#include
using namespace std;
int main()
{
char a[51],b[51];
int i,top;
while(gets(a)!=NULL)
{
top=-1;
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='{'||a[i]=='['||a[i]=='(')
{
b[++...
分类:
其他好文 时间:
2014-12-05 00:50:15
阅读次数:
179
#include
#include
using namespace std;
string a[20010],b[20010];
int main()
{
int n,m,i,flag;
string x,y;
while(cin>>n>>m)
{
flag=0;
int top=0;
int top1=0;
int top2=0;
for(i=0;i<m;i++)
...
分类:
其他好文 时间:
2014-12-05 00:49:43
阅读次数:
192
#include
using namespace std;
int youxian(char s)
{
if(s=='+'||s=='-') return 1;
else if(s=='*'||s=='/') return 2;
else if(s=='(') return 3;
else if(s==')') return 4;
}
int main()
{
int top=0;
...
分类:
其他好文 时间:
2014-12-05 00:49:26
阅读次数:
190
One: Using two stacks, stack to traversal the node, stackr to record the parent node when visiting its right-child; https://oj.leetcode.com/problems.....
分类:
其他好文 时间:
2014-12-05 00:30:18
阅读次数:
158
五道经典的OJ题目:24点游戏算法、周期串问题、删除重复字符、N皇后、可怕的阶乘。...
分类:
其他好文 时间:
2014-12-04 23:15:46
阅读次数:
376
#include
using namespace std;
int visit[10][10],a[10][10];
int n,m;
int k;
void dfs(int x,int y)
{
if(xn-1||ym-1||visit[x][y]||a[x][y])
return;
if(x==n-1 && y==m-1)
{
k++;
return ;
}
else
...
分类:
其他好文 时间:
2014-12-04 23:13:10
阅读次数:
252
关于eclipse的配置 我感觉我讲不清【逃开始从配好之后讲起文件名命名为Main.java【接下来几行解释为什么要起这个名字注意第七行那里(为了方便复制我没有加行号)的类的名字必须与文件名相同但是你会看到各大oj的FAQ上有一些要求比如hdu上有这个然后貌似我今年去鞍山打区域赛的时候也有这个要求 ...
分类:
编程语言 时间:
2014-12-04 21:22:10
阅读次数:
285
oj地址
题目1512:用两个栈实现队列
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:2360
解决:804
题目描述:
用两个栈来实现一个队列,完成队列的Push和Pop操作。
队列中的元素为int类型。
输入:
每个输入文件包含一个测试样例。
对于每个测试样例,第一行输入一个n(1
...
分类:
其他好文 时间:
2014-12-04 20:03:58
阅读次数:
157