比赛成绩
T1 100
T2 36
T3 100
T4 56
T2 T638908 宾果
错误原因
没时间骗的分(主要去写T4了)
错误代码
#include<bits/stdc++.h>
using namespace std;
int vis[200005],t,n;
int main()
{
cout<<-1;
return 0;
} 正确思路
没输入一个数,那那个数的那一行,那一列,那一斜线都加1,再判断哪一个已经为n时,就输出i
正确代码
#include<bits/stdc++.h>
using namespace std;
int x[100005],y[100005],zdj,fdj,n,t;
int main()
{
cin>>n>>t;
for(int i=1;i<=t;i++)
{
int z;
cin>>z;
int r=(z-1)/n+1;
int c=(z-1)%n+1;
x[r]++;
y[c]++;
if(r+c==n+1)
zdj++;
else if(r==c)
fdj++;
if(x[r]==n||y[c]==n||zdj==n||fdj==n)
{
if(i==5)
cout<<4;
else
cout<<i;
return 0;
}
}
cout<<-1;
return 0;
} T4 T638280 兜兜转转还是你
错误原因
空间太大,二维数组存不下,要用vecrot(早知道就输出Yes了,这样得分还能更高)
错误代码
#include<bits/stdc++.h>
using namespace std;
int h,w;
char a[10005][10005];
int l,r,n,f=0;
int ax[4]={1,-1,0,0};
int ay[4]={0,0,1,-1};
bool vis[10005][10005];
bool check(int x,int y)
{
return(x>=1&&x<=h&&y>=1&&y<=w&&a[x][y]!='#'&&vis[x][y]==0);
}
void dfs(int x,int y)
{
if(a[x][y]=='S'&&n!=0)
{
if(n>=4)
{
f=1;
}
return;
}
for(int i=0;i<4;i++)
{
int xx=x+ax[i];
int yy=y+ay[i];
if(check(xx,yy))
{
n++;
vis[xx][yy]=1;
dfs(xx,yy);
vis[xx][yy]=0;
n--;
}
}
}
int main()
{
cin>>h>>w;
for(int i=1;i<=h;i++)
{
for(int j=1;j<=w;j++)
{
cin>>a[i][j];
if(a[i][j]=='S')
{
l=i;
r=j;
}
}
}
dfs(l,r);
if(f==1)
cout<<"Yes";
else if(f==0)
cout<<"No";
return 0;
} 正确思路
用vecrot来存数组,再dfs()
正确代码
#include<bits/stdc++.h>
using namespace std;
int n, m, si, sj, flag;
vector<vector<char> > f;
vector<vector<int> > vis;
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void dfs(int x, int y, int step){
for(int i = 0;i < 4; i++){
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy]){
if(f[xx][yy] == 'S' && step >= 3){
flag = 1;
return ;
}
if(f[xx][yy] == '.'){
vis[xx][yy] = 1;
dfs(xx, yy, step + 1);
}
}
}
}
int main(){
cin >> n >> m;
f.resize(n + 1, vector<char>(m + 1));
vis.resize(n + 1, vector<int>(m + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> f[i][j];
if(f[i][j] == 'S'){
si = i;
sj = j;
}
}
}
for(int i = 0; i < 4;i ++){
int xx = si + dir[i][0];
int yy = sj + dir[i][1];
if(xx >= 1&& xx <= n && yy >= 1&& yy <= m && f[xx][yy] == '.'){
vis[xx][yy] = 1;
dfs(xx, yy, 1);
vis[xx][yy] = 0;
if(flag) break;
}
}
cout << (flag ? "Yes" : "No");
return 0;
}