1028: [JSOI2007]麻将
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 307 Solved: 135
[ Submit][ Status][ Discuss]
Description
Input
Output
Sample Input
1 1 2 2 3 3 5 5 5 7 8 8 8
Sample Output
6 7 9
首先枚举加了哪张牌
再枚举哪个是一对
然后贪心判断剩下的是否能凑成m对
贪心策略为从小到大看当前牌模3剩下的是否能跟跟他连着的两个牌配对
#include <iostream>
using namespace std;
int n,m,a[403],b[403],i,j,k,w,c[403];
bool ok;
int main ()
{
cin >> n >> m;
for (i=1;i<=3*m+1;i++)
{
cin >> k;
a[k]++;
}
w=0;
for (i=1;i<=n;i++)
{
a[i]++;
for (j=1;j<=n;j++)
if (a[j]>=2)
{
for (k=1;k<=n;k++) b[k]=a[k];
b[j]-=2;
ok=true;
for (k=1;k<=n;k++)
{
b[k]%=3;
if ((k+2>n)&(b[k]!=0))
{
ok=false;
break;
}
if ((b[k+1]<b[k])||(b[k+2]<b[k]))
{
ok=false;
break;
}
b[k+1]-=b[k];
b[k+2]-=b[k];
}
if (ok) break;
}
a[i]--;
if (ok)
{
w++;
c[w]=i;
}
}
if (w==0) cout << "NO";
else
{
cout << c[1];
for (i=2;i<=w;i++) cout << " " << c[i];
}
}
224



被折叠的 条评论
为什么被折叠?



