1、折点计数
题目链接:https://sim.csp.thusaac.com/contest/7/problem/0
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{int n;cin >> n;int a[1010];for(int i = 0; i < n; i++){cin >> a[i];}int ans = 0;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 << endl;return 0;
}
评测结果:
2、俄罗斯方块
题目链接:https://sim.csp.thusaac.com/contest/7/problem/1
思路:在板块与方格图对应列的范围内,通过遍历的方式来判断板块中数字为1的最后一行是否与方格图中数字为1的第一行或方格图的最底部对接,如果对接,则将方格图中与4个方块位置对应的0元素赋值为1即可。
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{int n;int a[25][20],b[14][14];for(int i = 1; i <= 15; i++){for(int j = 1; j <= 10; j++){cin >> a[i][j];}}for(int i = 1; i <= 4; i++){for(int j = 1; j <= 4; j++){cin >> b[i][j];}}cin >> n;for(int j = 1; j <= 10; j++){ //用于判断板块中数字为1的最后一行是否与方格图的最底部对接 a[16][j] = 1; }for(int i = 1; i <= 15; i++){bool flag = false;for(int j = i; j <= i+3; j++){for(int k = 1; k <= 4; k++){if(a[j+1][k+n-1] == 1 && b[j-i+1][k] == 1 && b[j-i+2][k] == 0){a[j][k+n-1] = b[j-i+1][k];for(int t = i; t <= i+3; t++){for(int v = 1; v <= 4; v++){if(b[t-i+1][v] == 1 && a[t][v+n-1] == 0)a[t][v+n-1] = 1;} }flag = true; break;}}if(flag == true)break;}if(flag == true)break;}for(int i = 1; i <= 15; i++){for(int j = 1; j <= 10; j++){cout << a[i][j] << " ";}cout << endl;}return 0;
}
评测结果: