1-折点计数
#include<iostream>
using namespace std;
const int maxn=10000;
int a[maxn];
int main(){
int n,count=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n-2;i++)
if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
count++;
printf("%d\n",count);
return 0;
}
2.俄罗斯方块
#include <iostream>
const int ROW = 15;
const int COL = 10;
const int N = 4;
int board[ROW+1][COL];
int block[N][N];
struct {
int row, col;
} coords[N];
using namespace std;
int main()
{
int row, col;
for(int i=0; i<ROW; i++)
for(int j=0; j<COL; j++)
cin >> board[i][j];
for(int i=0; i<N; i++)
for(int j=0; j<N; j++)
cin >> block[i][j];
cin >> col;
for(int j=0; j<COL; j++)
board[ROW][j] = 1;
int k = 0;
for(int i=N-1; i>=0; i--)
for(int j=0; j<N; j++)
if(block[i][j] == 1) {
coords[k].row = i;
coords[k].col = j;
k++;
}
row = 1;
col--;
bool checkflag;
for(;;) {
checkflag = false;
for(int i=0; i<N; i++)
if(board[row + coords[i].row][col + coords[i].col] == 1) {
checkflag = true;
break;
}
if(checkflag)
break;
row++;
}
row--;
for(int i=0; i<N; i++)
board[row + coords[i].row][col + coords[i].col] = 1;
for(int i=0; i<ROW; i++) {
for(int j=0; j<COL; j++) {
if(j != 0)
cout << " ";
cout << board[i][j];
}
cout << endl;
}
return 0;
}
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0
1 1 1 0 0 0 1 1 1 1
0 0 0 0 1 0 0 0 0 0
0 0 0 0
0 1 1 1
0 0 0 1
0 0 0 0
3
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 0 0 0 0
3.路径解析
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main(){
int p,flag;
string s,t;
scanf("%d",&p);
getchar();
getline(cin,s);
for(int i=1;i<=p;i++){
getline(cin,t);
if(t.size()==0){
t=s;
}
if(t[0]!='/'){
t=s+'/'+t;
}
while(t[t.length()-1]=='/'&&t.length()>1){
t=t.substr(0,t.length()-1);
}
while((flag=(int)t.find("//"))!=-1){
t.erase(flag,1);
}
while((flag=(int)t.find("/./"))!=-1){
t.erase(flag,2);
}
while((flag=(int)t.find("/../"))!=-1){
if(flag==0){
t.erase(flag,3);
}else{
int count=4;
while(flag>=1&&t[flag-1]!='/'){
flag--;
count++;
}
t.erase(flag,count);
}
}
cout<<t<<endl;
}
}
7
/d2/d3
/d2/d4/f1
../d4/f1
/d1/./f1
/d1///f1
/d1/
///
/d1/../../d2
/d2/d4/f1
/d2/d4/f1
/d1/f1
/d1/f1
/d1
/
/d2
4.游戏
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 100;
const int DIRECTSIZE = 4;
struct node {
int row, col, level;
};
struct direct {
int drow, dcol;
} direct[DIRECTSIZE] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int visited[N+1][N+1][300+1];
int n,m;
int bfs()
{
node start;
start.row = 1;
start.col = 1;
start.level = 0;
queue<node> q;
q.push(start);
while(!q.empty()) {
node front;
front = q.front();
q.pop();
if(front.row == n && front.col == m)
return front.level;
for(int i=0; i<DIRECTSIZE; i++) {
node v;
v.row = front.row + direct[i].drow;
v.col = front.col + direct[i].dcol;
v.level = front.level + 1;
if(v.row < 1 || v.row > n || v.col < 1 || v.col > m)
continue;
if(visited[v.row][v.col][v.level])
continue;
q.push(v);
visited[v.row][v.col][v.level] = 1;
}
}
return 0;
}
int main()
{
int t, r, c, a, b;
memset(visited, 0, sizeof(visited));
cin >> n >> m >> t;
for(int i=1; i<=t; i++) {
cin >> r >> c >> a >> b;
for(int j=a; j<=b; j++)
visited[r][c][j] = 1;
}
int ans = bfs();
cout << ans << endl;
return 0;
}
3 3 3
2 1 1 1
1 3 2 10
2 2 2 10
6
5.无线网络