记录编号 |
48789 |
评测结果 |
AAAWWWWWWWWWWWW |
题目名称 |
二十一点 |
最终得分 |
20 |
用户昵称 |
Truth.Cirno |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.006 s |
提交时间 |
2012-11-06 15:58:30 |
内存使用 |
3.15 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,num[1010],maxwin;
bool rec[1010];
void work(void)
{
int i,yours,mine,win=0;
bool youhaveright,Ihaveright;
for (i=1;i+5<=n;)
{
yours=0;
mine=0;
youhaveright=true;
Ihaveright=true;
if (rec[i]==0&&rec[i+1]==1&&rec[i+2]==0&&rec[i+3]==1)
{
yours+=num[i++];
mine+=num[i++];
yours+=num[i++];
mine+=num[i++];
}
else
{
return;
}
while (i<=n)
{
if (youhaveright&&yours<=16)
{
if (rec[i]==0)
yours+=num[i++];
else
return;
if (yours>21)
{
win++;
break;
}
if (i>n)
{
if (mine>yours)
win++;
break;
}
}
else
{
youhaveright=false;
}
if (Ihaveright)
{
if (youhaveright)
{
if (rec[i]==1)
{
mine+=num[i++];
}
else
{
Ihaveright=false;
continue;
}
if (mine>21)
{
break;
}
if (i>n)
{
if (mine>yours)
win++;
break;
}
}
else
{
if (mine>yours)
{
win++;
break;
}
if (rec[i]==1)
{
mine+=num[i++];
}
else
{
Ihaveright=false;
break;
}
if (mine>21)
{
break;
}
if (mine>yours)
{
win++;
break;
}
if (i>n)
break;
}
}
else
{
if (!youhaveright)
{
if (mine>yours)
win++;
break;
}
}
}
}
maxwin=max(maxwin,win);
}
void dfs(int deep)
{
if (deep>n)
{
work();
return;
}
rec[deep]=0;
dfs(deep+1);
rec[deep]=1;
dfs(deep+1);
}
int main(void)
{
freopen("jack.in","r",stdin);
freopen("jack.out","w",stdout);
int i;
cin>>n;
for (i=1;i<=n;i++)
cin>>num[i];
if (n>20)
{
int yours,mine,win=0;
bool youhaveright,Ihaveright;
for (i=1;i+5<=n;)
{
yours=0;
mine=0;
youhaveright=true;
Ihaveright=true;
yours+=num[i++];
mine+=num[i++];
yours+=num[i++];
mine+=num[i++];
while (i<=n)
{
if (youhaveright&&yours<=16)
{
yours+=num[i++];
if (yours>21)
{
win++;
break;
}
if (i>n)
{
if (mine>yours)
win++;
break;
}
}
else
{
youhaveright=false;
}
if (Ihaveright)
{
if (youhaveright)
{
mine+=num[i++];
if (mine>21)
{
mine-=num[--i];
Ihaveright=false;
}
if (i>n)
{
if (mine>yours)
win++;
break;
}
}
else
{
if (mine>yours)
{
win++;
break;
}
mine+=num[i++];
if (mine>21)
{
i--;
break;
}
if (mine>yours)
{
win++;
break;
}
if (i>n)
break;
}
}
else
{
if (!youhaveright)
{
if (mine>yours)
win++;
break;
}
}
}
}
cout<<win<<endl;
}
else
{
rec[1]=0;
dfs(2);
rec[1]=1;
dfs(2);
cout<<maxwin<<endl;
}
return(0);
}