实现
#include
using namespace std;
const int N = 1010;
int a[N];
int n;
int ans;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<n-1;i++)
{
if((a[i]>a[i+1] && a[i]>a[i-1])||(a[i]<a[i-1] && a[i]<a[i+1]))
ans++;
}
cout<<ans;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
实现
#include
#include
#include
using namespace std;
const int N = 17;
int g[N][N], st[N][N];
int p[4][4];
bool draw(int x, int y)
{
memcpy(st, g, sizeof st);
for (int i = 0; i < 4; i ++)
for (int j = 0; j < 4; j ++)
{
if (p[i][j])
{
int a = x + i, b = y + j;
st[a][b] ++;
if (st[a][b] == 2) return true;
}
}
return false;
}
int main()
{
for (int i = 0; i < 15; i ++)
for (int j = 0; j < 10; j ++)
cin >> g[i][j];
for (int i = 0; i < 4; i ++)
for (int j = 0; j < 4; j ++)
cin >> p[i][j];
for (int j = 0; j < 10; j ++) g[15][j] = 1;
int c;
cin >> c;
c --;
for (int i = 0; ; i ++)
{
if (draw(i, c))
{
draw(i-1, c);
break;
}
}
for (int i = 0; i < 15; i ++)
{
for (int j = 0; j < 10; j ++)
cout << st[i][j] << " ";
cout << endl;
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
实现
#include
#include
#include
#include
using namespace std;
int n;
vector<string> path;
vector<string> curr;
vector<string> get(string t)
{
vector<string> tmp;
for (int i = 0; i < t.size(); i++)
{
if (t[i] == '/') continue ;
int j = i + 1;
while (t[j] != '/' && j < t.size())
{
j++;
}
tmp.push_back(t.substr(i, j - i));
i = j - 1;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
实现
#include
using namespace std;
int n,m,t;
const int N = 110;
bool g[N][N][10010];
int dist[N][N][310];
struct node
{
int x,y,time;
}nodes[110*110*310];
int bfs()
{
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
queue<node> q;
q.push({1,1,0});
memset(dist,0x3f,sizeof dist);
while(q.size())
{
auto t = q.front();
q.pop();
for(int i=0;i<4;i++)
{
int xx = t.x+dx[i],yy = t.y+dy[i],tt = t.time+1;
if(g[xx][yy][tt]) continue;
if(xx<1 ||xx>n || yy<1 ||yy>m ) continue;
if(dist[xx][yy][tt]>tt)
{
dist[xx][yy][tt] = tt;
q.push({xx,yy,tt});
if(xx==n &&yy==m) return tt;
}
}
}
return 0;
}
int main()
{
cin>>n>>m>>t;
int x,y,t1,t2;
while(t--)
{
cin>>x>>y>>t1>>t2;
for(int i=t1;i<=t2;i++)
g[x][y][i] = 1;
}
cout<<bfs()<<endl;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49