第13次CCF CSP认证真题解
1、跳一跳
题目链接:https://sim.csp.thusaac.com/contest/13/problem/0
本题是小游戏“跳一跳”的模拟题,按照题意模拟即可。
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n = 30;
int sum = 0,t = 0;
int a[40];
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 0)break;
else if(a[i] == 1){
sum += a[i];
t = 0;
}
else if(a[i] == 2){
t++;
sum += t*2;
}
}
cout << sum << endl;
return 0;
}
评测结果:
2、碰撞的小球
题目链接:https://sim.csp.thusaac.com/contest/13/problem/1
本题属于简单的运动学模拟题,根据小球的运动流程模拟出算法的操作流程即可。
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n,L,t;
cin >> n >> L >> t;
int a[110],b[110],c[110];
for(int i = 1; i <= n; i++){
cin >> a[i];
b[i] = a[i];
}
int time = 1;
while(time <= t){
int index[110],k = 1;
for(int i = 1; i <= n; i++){
for(int j = i+1; j <= n; j++){
if(a[i] == a[j]){
index[k] = i; k++;
index[k] = j; k++;
}
}
if(a[i] == 0){
index[k] = i;
k++;
}
if(a[i] == L){
index[k] = i;
k++;
}
}
for(int j = 1; j <= n; j++){
int count = 0;
for(int t = 1; t < k; t++){
if(j == index[t]){
if(a[j] - c[j] < 0 && a[j] != 0 && a[j] != L)a[j]++;
else if(a[j] - c[j] > 0 && a[j] != 0 && a[j] != L)a[j]--;
else if(a[j] == 0)a[j]++;
else if(a[j] == L)a[j]--;
}
else count++;
}
if(count == k-1){
if(a[j] - c[j] < 0 && time > 1)a[j]--;
else if(a[j] - c[j] > 0 && time > 1)a[j]++;
else if(time == 1)a[j]++;
}
}
time++;
for(int j = 1; j <= n; j++){
c[j] = b[j];
}
for(int j = 1; j <= n; j++){
b[j] = a[j];
}
}
for(int k = 1; k <= n; k++){
cout << a[k] << " ";
}
cout << endl;
return 0;
}
评测结果: