L1最后一道 L2的前三道皆因为各种原因最后几个测试点出现段错误(也有部分测试点答案错误 )没有拿全部分数。。。
(L2最后一道其实也是段错误,只不过最后改过来了)
段错误段的我人都傻了
先说L1最后一道题 少考虑了乘法结果的末尾为0的情况
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
int sum[maxn],n;
int main()
{
cin>>sum[0]>>sum[1]>>n;
for(int i=2,j=2; j<n; ++i)
{
int tmp=sum[i-1]*sum[i-2];
if(tmp==0)///!!!!比赛的时候就因为这个!!
sum[j++]=tmp;
else
{
stack<int>t;
while(tmp)
{
t.push(tmp%10);
tmp/=10;
}
while(!t.empty())
{
sum[j++]=t.top();
t.pop();
}
}
}
for(int i=0; i<n; ++i)
{
if(i==0)
cout<<sum[i];
else
cout<<' '<<sum[i];
}
return 0;
}
L2第一道题
模拟题 注意各种限制条件
L2 包装机
#include <bits/stdc++.h>
using namespace std;
int n,m,s;
//char mp[105];
string ss[105];
int top[105];
char stk[105];
int sum;
string ans="";
int main()
{
cin>>n>>m>>s;
for(int i=1; i<=n; i++)
{
cin>>ss[i];
}
int x;
while(cin>>x)
{
if(x==-1)break;
if(x!=0)
{
if(top[x]==m)continue;
if(sum==s)
{
ans+=stk[--sum];
}
stk[sum++]=ss[x][top[x]++];
}
else
{
if(sum>0)
ans+=stk[--sum];
}
}
cout<<ans<<endl;
return 0;
}
L2第二道题
dfs 栈记录路径 注意第一个病毒不确定需要通过入度确定
L2 病毒溯源
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
vector<int>mp[maxn];
int n,m,S;
int in[maxn];
int stk[maxn],top;
int stt[maxn],dep;
bool ok()
{
for(int i=0; i<top; i++)
{
if(stt[i]<stk[i])
{
for(; i<top; i++)
{
stk[i]=stt[i];
}
return true;
}
else if(stt[i]>stk[i])
return false;
}
return false;
}
void dfs(int s)
{
if(mp[s].size()==0)
{
if(top==dep&&ok());
else if(top<dep)
{
top=dep;
for(int i=0; i<dep; i++)
{
stk[i]=stt[i];
}
}
}
for(int i=0; i<mp[s].size(); i++)
{
stt[dep++]=mp[s][i];
dfs(mp[s][i]);
dep--;
}
}
int main()
{
cin>>n;
for(int i=0; i<n; i++)
{
int k;
cin>>k;
while(k--)
{
cin>>m;
mp[i].push_back(m);
in[m]++;
}
}
for(int i=0; i<n; i++)
{
if(!in[i])
{
S=i;
break;
}
}
//考试的时候我好像这两句有问题 (..但怎么可能没检查出来呢)
//但是当时肯定知道首节点需要通过入度查找
stk[top++]=S;
stt[dep++]=S;
dfs(S);
cout<<top<<endl;
for(int i=0; i<top; i++)
{
if(i==0)
cout<<stk[i];
else
cout<<" "<<stk[i];
}
return 0;
}