zoj 3757 Alice and Bob and Cue Sports 月赛A 模拟

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757

题意:根据所给的台球规则,按照每次的结果计算最终两人的得分

单纯的模拟题,分支比较多写起来较繁琐

注意区分犯规与进球得分的规则:

只要有犯规行为,都要按照规则给对手加分。无论是否进球。

当进球时,如果有犯规行为,不仅分要加给对手,还要加上犯规惩罚

  1 #include<cmath>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<iostream>
  5 #include<algorithm>
  6 using namespace std;
  7 #define maxn 10005
  8 int v[1005];
  9 int a,b;
 10 bool flag;//碰谁了
 11 bool flag1;//先碰的球ok
 12 bool flag2;//有球进球
 13 bool flag4;//没碰到球
 14 bool flag3;//target
 15 bool flag0;//白球进洞
 16 int _min,_max;
 17 int firsth;//最大的
 18 int vis[maxn];
 19 int low,high;
 20 
 21 
 22 int main()
 23 {
 24     int n,m,i;
 25     flag=true;
 26     while(~scanf("%d%d",&n,&m))
 27     {
 28         flag=true;
 29         a=b=0;
 30         for(i=1;i<=n;i++)
 31             scanf("%d",&v[i]);
 32         sort(v,v+n);
 33         low=1;//high=n;
 34         _min=v[1];//_max=v[n];
 35         memset(vis,false,sizeof(vis));
 36         while(m--)
 37         {
 38             int p,q;
 39             scanf("%d",&p);
 40             flag4=false;
 41             if(p!=1)
 42             {
 43                 if(p==0)
 44                 {
 45                     flag4=true;
 46                 }
 47                 else
 48                 {
 49                 flag1=false;
 50                 int x;
 51                 firsth=0;
 52                 while(p--)
 53                 {
 54                     scanf("%d",&x);
 55                     if(x>firsth)
 56                         firsth=x;
 57                 }
 58                 }
 59             }
 60             else
 61             {
 62                 scanf("%d",&p);
 63                 if(p!=_min)
 64                     flag1=false;
 65                 else
 66                     flag1=true;
 67                 firsth=p;
 68             }
 69             scanf("%d",&q);//进的球
 70             if(q==0)
 71                 flag2=false;
 72             else
 73                 flag2=true;
 74             int all=0;
 75             int y;
 76             flag0=false;
 77             flag3=false;
 78             for(i=0;i<q;i++)
 79             {
 80                 scanf("%d",&y);
 81                 if(y==0)
 82                 {
 83                     flag0=true;//白球进洞
 84                 }
 85                 if(y==_min)
 86                 {
 87                     flag3=true;//target
 88                 }
 89                 all+=y;
 90                 vis[y]=true;
 91             }
 92             if(flag4)//没碰到任何球
 93             {
 94                 if(flag)
 95                     b+=_min;
 96                 else
 97                     a+=_min;
 98                 flag=!flag;
 99             }
100             else//碰到球了
101             {
102                 if(flag0)//白球进洞
103                 {
104                     if(flag)b+=firsth+all;
105                     else a+=firsth+all;
106                     flag=!flag;
107                 }
108                 else//白球没进洞
109                 {
110                     if(flag2)//有球进洞
111                     {
112                         if(flag3)//target
113                         {
114                             if(flag1)
115                             {
116                                 if(flag)a+=all;
117                                 else b+=all;
118                             }
119                             else//没有先碰target进球了
120                             {
121                                 if(flag)b+=all+firsth;
122                                 else a+=all+firsth;
123                                 flag=!flag;
124                             }
125                         }
126                         else
127                         {
128                             if(!flag1)
129                             {
130                                 if(flag)b+=firsth;
131                                 else a+=firsth;
132                             }
133                             if(flag)b+=all;
134                             else a+=all;
135                             flag=!flag;
136                         }
137                     }
138                     else//没球进洞
139                     {
140                         if(!flag1)
141                         {
142                         if(flag)
143                             b+=firsth;
144                         else a+=firsth;
145                         }
146                         flag=!flag;
147                     }
148                 }
149             }
150             if(vis[_min])
151             {
152                 while(vis[v[low]]&&low<=n)
153                 {
154                     low++;
155                 }
156                 _min=v[low];
157             }
158         }
159         printf("%d : %d
",a,b);
160     }
161     return 0;
162 }
View Code

(P.S.写的比较丑陋,分支可以优化)

原文地址:https://www.cnblogs.com/wuwing/p/3577085.html