CCF CSP历年一二题代码汇总

Posted qaqorz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CCF CSP历年一二题代码汇总相关的知识,希望对你有一定的参考价值。

实话说如果不是为了骗访问量,才不会写12题的qwq

 

201803-1 跳一跳

第一题向来是送分题。。。但是注意读题。。。

模拟题按题意走是坠稳的

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define LL long long
 6 #define debug(x) cout << "[" << x << "]" << endl
 7 using namespace std;
 8 
 9 int main(){
10     int ans = 0, last = 0, n;
11     while (scanf("%d", &n) == 1 && n){
12         if (n == 2){
13             if (ans == 0 || last == 1){
14                 last = 2;
15                 ans += 2;
16             }
17             else {
18                 last += 2;
19                 ans += last;
20             }
21         }
22         else {
23             ans++;
24             last = 1;
25         }
26     }
27     printf("%d
", ans);
28     return 0;
29 }
View Code

 

 

201803-2 碰撞的小球

t只有100,n也只有100,tn^2随便模拟一下。。

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define LL long long
 6 #define debug(x) cout << "[" << x << "]" << endl
 7 using namespace std;
 8 
 9 int a[110], b[110];
10 
11 int main(){
12     int n, l, t;
13     scanf("%d%d%d", &n, &l, &t);
14     for (int i = 1; i <= n; i++){
15         scanf("%d", &a[i]);
16         b[i] = 1;
17     }
18     while (t--){
19         for (int i = 1; i <= n; i++){
20             for (int j = i+1; j <= n; j++){
21                 if (i == j) continue;
22                 if (a[i] == a[j]){
23                     b[i] = -b[i];
24                     b[j] = -b[j];
25                 }
26             }
27             if (a[i] == 0 || a[i] == l) b[i] = -b[i];
28         }
29         for (int i = 1; i <= n; i++) a[i] += b[i];
30     }
31     for (int i = 1; i <= n; i++)
32         printf("%d%c", a[i], i == n ? 
 :  );
33     return 0;
34 }
View Code

 

201712-1 最小差值

暴力或排序随便怎么实现都行

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define INF 0x3f3f3f3f
 6 #define LL long long
 7 #define debug(x) cout << "[" << x << "]" << endl
 8 using namespace std;
 9 
10 int a[1010];
11 
12 int main(){
13     int n;
14     scanf("%d", &n);
15     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
16     sort(a+1, a+n+1);
17     int ans = INF;
18     for (int i = 1; i < n; i++)
19         ans = min(ans, a[i+1]-a[i]);
20     printf("%d
", ans);
21     return 0;
22 }
View Code

 

201712-2 游戏

写个死循环模拟到只剩一个人为止

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define LL long long
 6 #define debug(x) cout << "[" << x << "]" << endl
 7 using namespace std;
 8 
 9 bool vis[1010];
10 
11 int main(){
12     int n, k, num = 0, sum = 0;
13     scanf("%d%d", &n, &k);
14     while (1){
15         for (int i = 1; i <= n; i++){
16             if (vis[i]) continue;
17             num++;
18             if (num%10 == k || num%k == 0) {
19                 vis[i] = 1;
20                 sum++;
21             }
22             if (sum == n-1) break;
23         }
24         if (sum == n-1) break;
25     }
26     for (int i = 1; i <= n; i++){
27         if (!vis[i]){
28             printf("%d
", i);
29             break;
30         }
31     }
32     return 0;
33 }
View Code

 

201709-1 打酱油

算就行

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #define LL long long
 6 #define debug(x) cout << "[" << x << "]" << endl
 7 using namespace std;
 8 
 9 int main(){
10     int n, ans = 0;
11     scanf("%d", &n);
12     n /= 10;
13     ans += n/5*7;
14     n %= 5;
15     ans += n/3*4;
16     n %= 3;
17     ans += n;
18     printf("%d
", ans);
19     return 0;
20 }
View Code

 

以上是关于CCF CSP历年一二题代码汇总的主要内容,如果未能解决你的问题,请参考以下文章

新CCF-CSP认证历年真题解

算法题CCF CSP第二题练习(更新中)

CCF CSP个人题解汇总

CCF CSP 202109赛题练习

2020年csp第一轮认证分数线

CCF-CSP 201604 赛题训练