###### weixin_43367986

2018-11-10 17:12 浏览 553

# 不知道怎么写代码,望大神告诉思路和源代码

10
3
2 4
5 -3
8 -2
5
2
2 5
3 4
2
5 2
4 3
2
5 2
4 2
3
4 2
3 1
2 2
2
6 5
6 9

A wins a game
B wins a game
Both none
A equal B
A equal B

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答

#### 2条回答默认 最新

• 已采纳
weixin_43367986 2018-11-11 06:42

#include
int main() {
int n, m, i, v, s, k, sa, sb, h, j, A, B,road[10000];//A,B分别存储A和B的运动情况
scanf("%d%d", &n, &m);

``````for (h = 0; h < n; h++)     //初始化路上奖惩
for (h = 0; h < m; h++) {   //输入奖惩
scanf("%d%d", &i, &v);
}
scanf("%d", &k);
for (h = 0; h < k; h++) {
A = B = 0;          //重置A、B位置
scanf("%d", &s);
for (j = 0; j < s; j++) {
scanf("%d%d", &sa, &sb);
A += sa;
if(A<n-1)   //A未到终点前，判断奖惩
B += sb;
if(B<n-1)   //同上
}
if (A >= n - 1 && B >= n - 1)   //判断结果
printf("A equal B\n");
else if (A >= n - 1)
printf("A wins a game\n");
else if (B >= n - 1)
printf("B wins a game\n");
else
printf("Both none\n");
}
return 0;
``````

}

``````答题思路是建立两条道路,一条没有奖惩值,一条只有奖惩值,两条道路的相加得出总部数值,最后合并判断.
``````
点赞 评论 复制链接分享

看注释

`````` #include<stdio.h>
int main() {
int n, m, i, v, s, k, sa, sb, h, j, tmp, A, B;//A,B分别存储A和B的运动情况
scanf("%d%d", &n, &m);
for (h = 0; h < n; h++)     //初始化路上奖惩
for (h = 0; h < m; h++) {   //输入奖惩
scanf("%d%d", &i, &v);
}
scanf("%d", &k);
for (h = 0; h < k; h++) {
A = B = 0;          //重置A、B位置
scanf("%d", &s);
for (j = 0; j < s; j++) {
scanf("%d%d", &sa, &sb);
A += sa;
if(A<n-1)   //A未到终点前，判断奖惩
B += sb;
if(B<n-1)   //同上
}
if (A >= n - 1 && B >= n - 1)   //判断结果
printf("A equal B\n");
else if (A >= n - 1)
printf("A wins a game\n");
else if (B >= n - 1)
printf("B wins a game\n");
else
printf("Both none\n");
}
return 0;
}
``````
点赞 评论 复制链接分享