首页 > 代码库 > URAL 1804 The Machinegunners in a Playoff (比较绕的分类)
URAL 1804 The Machinegunners in a Playoff (比较绕的分类)
题目链接:URAL 1804 The Machinegunners in a Playoff
题意:给出M队上一场(主场或客场)得分和失分(对方进球),求下一场M队的比赛策略
比赛的规则:2场比赛,两队分别依次主场。1.总分大的胜利。2.总分相同,客场得分多的胜利。3.两者都相同,两队都有可能获胜。每队一场得分不超过30分
策略:1.M队可能晋级的最小分数,2.M队使C队可能晋级的最大分数。
思路:求最小:C队得分0。求最大:C队得分30分。关键是比较每次两队的客场得分。
AC代码:
#include<stdio.h> #include<string.h> int main() { int a,b; int t,i,min,max; char s[10][100]; while(scanf("%d",&t)!=EOF) { while(t--) { scanf("%s%s%s%s%s%s %d %s%s%s %d %s",s[0],s[1],s[2],s[3],s[4],s[5],&a,s[6],s[7],s[8],&b,s[9]); if(strcmp(s[3],"home")==0)//Machinegunners主场 { //a+x=b min=b-a;//总球数相同 M客场进min球 C客场进b球 if(min>=0 && min<b) min++; else if(min<0) min=0; //a+max=b+30 max=30+b-a;//总球数相同 M客场进max球 C客场进b球 if(max<=30 && max>b) max--; else if(max>30) max=30; } else { min=b-a;//总球数相同 M客场进a球 C客场进0球 if(min>=0 && a<0) min++; else if(min<0) min=0; //a+max=b+30 max=30+b-a; if(max<=30 && a>30) max--; else if(max>30) max=30; } printf("%d %d\n",min,max); } } return 0; } /* 10 The Machinegunners played home game, scored 30 goals, and conceded 30 goals. The Machinegunners played away game, scored 30 goals, and conceded 30 goals. The Machinegunners played home game, scored 3 goals, and conceded 3 goals. The Machinegunners played away game, scored 3 goals, and conceded 5 goals. The Machinegunners played away game, scored 30 goals, and conceded 0 goals. */
AC代码(模拟)
详细:http://blog.csdn.net/kewowlo/article/details/38149569
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int Min(int a,int b) { return a>b?b:a; } int main() { int a,b; int t,len,i,m; char s[10][100]; while(scanf("%d",&t)!=EOF) { while(t--) { scanf("%s%s%s%s%s%s %d %s%s%s %d %s",s[0],s[1],s[2],s[3],s[4],s[5],&a,s[6],s[7],s[8],&b,s[9]); if(strcmp(s[3],"home")==0)//Machinegunners主场 { //a赢求,b是输球 for(i=0;i<=30;i++) { if(i+a>b) { printf("%d ",i); break; } else if(i+a==b && i>=b) { printf("%d ",i); break; } } for(i=30;i>=0;i--) { if(i+a<b+30) { printf("%d\n",i); break; } else if(i+a==b+30 && i<=b) { printf("%d\n",i); break; } } } else//客场 { for(i=0;i<=30;i++) { if(i+a>b) { printf("%d ",i); break; } else if(i+a==b) { printf("%d ",i); break; } } for(i=30;i>=0;i--) { if(i+a<b+30 && i>=b) { printf("%d\n",i); break; } else if(i+a==b+30 && a<=30) { printf("%d\n",i); break; } } } } } return 0; } /* 2 The Machinegunners played home game, scored 29 goals, and conceded 4 goals. The Machinegunners played away game, scored 0 goals, and conceded 0 goals. The Machinegunners played home game, scored 3 goals, and conceded 3 goals. The Machinegunners played away game, scored 3 goals, and conceded 5 goals. The Machinegunners played away game, scored 30 goals, and conceded 0 goals. 0 0 0 29 30 30 1 30 */
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。