训练赛后补题 07

2020-07-01 个人训练赛后补题

放题:

 

 题面翻译:

chef,chefu和chefina在为了争论他们三人中谁是石头剪刀布玩得最好的人吵架。现在为了得出这个答案,他们决定主持一场比赛来找出他们中最好的玩家。他们决定玩n局游戏。
但是他们没有裁判员来追踪(?)分数表【意思大概是没人帮他们判分吧】。帮助他们计算分数表吧!
游戏规则和分数说明如下:
R石头,P布,S剪刀;克制+1,被克制-1,同样的不算分。
##input
第一行 T,指T个测试样例
第二行N,指n局
接下来n行各三个字母,分别为chef、chefu和chefina的出招
##output
每行分别输出chef、chefu和chefina的分数
##constraints
1<=T<=100
2<=N<=10000

//-----------------------------

训练时WA代码:【runtime error】

 1 #pragma warning (disable:4996)
 2 #include <iostream>
 3 #include<algorithm>
 4 #include<stdio.h>
 5 #include<math.h>
 6 #include<string.h>
 7 #include<string>
 8 #define MAX1 400005            /*4e5 + 5*/
 9 #define MAX2 1000000005        /*le9 + 5*/
10 #define MAX3 200005            /*1e5 + 5*/
11 #define MAX4 5005            /*5e4 + 5*/
12 #define T2 27
13 #define T3 18
14 using namespace std;
15 typedef long long int ll;
16 #define MOL 998244353
17 
18 int movea(char a, char b) {
19     if (a == 'R') {
20         if (b == 'P')
21             return -1;
22         if (b == 'S')
23             return 1;
24     }
25     if (a == 'P') {
26         if (b == 'S')
27             return -1;
28         if (b == 'R')
29             return 1;
30     }
31     if (a == 'S') {
32         if (b == 'R')
33             return -1;
34         if (b == 'P')
35             return 1;
36     }
37     return 0;
38 }
39 int main() {
40     int t, cf[5] = { 0 };
41     while (scanf("%d", &t) != EOF) {
42         cf[0] = cf[1] = cf[2] = 0;
43         for (int k = 0; k < t; ++k) {
44             int n = 0;
45             scanf("%d", &n);
46             for (int i = 0; i < n; ++i) {
47                 char x, y, z;
48                 getchar();
49                 scanf("%c %c %c", &x, &y, &z);
50                 cf[0] += movea(x, y);
51                 cf[0] += movea(x, z);
52                 cf[1] += movea(y, x);
53                 cf[1] += movea(y, z);
54                 cf[2] += movea(z, x);
55                 cf[2] += movea(z, y);
56             }
57             printf("%d %d %d\n", cf[0], cf[1], cf[2]);
58         }
59     }
60     return 0;
61 }

 

上网查了一下(下面为复制黏贴)

 

 

我看了一下自己的代码,从virtual judge跳转到codechef试着过了一下代码,可能bug:

①某个测试样例中爆栈

②某个测试样例死循环

 这几天感觉 virtual judge 提交很不稳定,不知道为啥。

AC了,两个原因都不是……代码本身逻辑没得问题,对字符输入改成cin输入就好了。

之前的 runtime error 具体可能是网站测试数据库排版的原因吧。

下面贴AC代码:

 1 #pragma warning (disable:4996)
 2 #include <iostream>
 3 #include<algorithm>
 4 #include<stdio.h>
 5 #include<math.h>
 6 #include<string.h>
 7 #include<string>
 8 #define MAX1 400005            /*4e5 + 5*/
 9 #define MAX2 1000000005        /*le9 + 5*/
10 #define MAX3 200005            /*1e5 + 5*/
11 #define MAX4 5005            /*5e4 + 5*/
12 #define T2 27
13 #define T3 18
14 using namespace std;
15 typedef long long int ll;
16 #define MOL 998244353
17 
18 int movea(char a, char b) {
19     if (a == 'R') {
20         if (b == 'P')
21             return -1;
22         if (b == 'S')
23             return 1;
24     }
25     if (a == 'P') {
26         if (b == 'S')
27             return -1;
28         if (b == 'R')
29             return 1;
30     }
31     if (a == 'S') {
32         if (b == 'R')
33             return -1;
34         if (b == 'P')
35             return 1;
36     }
37     return 0;
38 }
39 int main() {
40     int t, cf[5] = { 0 };
41     while (scanf("%d", &t) != EOF) {
42         for (int k = 0; k < t; ++k) {
43             int n = 0;
44             scanf("%d", &n);
45             cf[0] = cf[1] = cf[2] = 0;
46             for (int i = 0; i < n; ++i) {
47                 char x, y, z;
48                 cin >> x >> y >> z;
49                 cf[0] += movea(x, y);
50                 cf[0] += movea(x, z);
51                 cf[1] += movea(y, x);
52                 cf[1] += movea(y, z);
53                 cf[2] += movea(z, x);
54                 cf[2] += movea(z, y);
55             }
56             printf("%d %d %d\n", cf[0], cf[1], cf[2]);
57         }
58     }
59     return 0;
60 }

 

posted @ 2020-07-11 15:40  听说福建人很好吃  阅读(146)  评论(0)    收藏  举报