| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:终于不打表AC,282ms,放出代码,求更快的解法……In Reply To:Re:终于不打表AC,282ms,放出代码,求更快的解法…… Posted by:iphone3gs at 2009-12-19 21:48:00 #include <iostream>
using namespace std;
int array[14]={0};
int main()
{
//ifstream in("input.dat");
//ofstream out("output.dat");
int nGoodGuys;
int nTestSolution;
int pos=1;
bool bBingo=true;
int nSizeQueue=0;
while (1)
{
cin>>nGoodGuys;
if(0==nGoodGuys)
break;
//assert(nGoodGuys<14&& nGoodGuys>0);
if(array[nGoodGuys]!=0)
{
cout<<array[nGoodGuys]<<endl;
continue;
}
for (int base=1;;base++)
{
for (int i=0;i<=1;i++)
{
nTestSolution=base*(nGoodGuys+1)+i;
bBingo=true;
nSizeQueue=2*nGoodGuys;
pos=1;
for (int j=0;j<nGoodGuys;j++)
{
pos=(pos+nTestSolution-1)%nSizeQueue;
if(0==pos)
pos=nSizeQueue;
if(pos<nGoodGuys+1)
{
bBingo=false;
break;
}
if(nSizeQueue==pos)
pos=1;
nSizeQueue--;
}
if (bBingo)
{
cout<<nTestSolution<<endl;
array[nGoodGuys]=nTestSolution;
break;
}
}
if (bBingo)
break;
}
}
return 0;
}
//32ms通过
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator