| ||||||||||
| 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 | |||||||||
给一个暴力模拟的代码。。。int ans[15]={-1,2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};
以下是暴力模拟。。。答案当然是打表啦。。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
using namespace std;
int n;
int i,j;
int k,h;
int max(int a,int b)
{return a<b?b:a;}
vector <int >sb;
vector <int >::iterator it;
int main()
{
while(cin>>k&&k)
{
int line=0;
int m;
for (i=1;i<=20000000;i++) //随便设置的次数
{
line=!line;
if (!line)
m=i*(k+1)+1; //只有 (k+1)的倍数加1或者0 才可能是答案
else
m=i*(k+1);
if (line) i--;
sb.clear();
for (j=1;j<=k;j++)
sb.push_back(1);
for (j=1;j<=k;j++)
sb.push_back(2);
int kill=0;
int p=0;
while(1)
{
p=(p+m-1)%sb.size(); //暴力模拟
if (sb[p]==2)
{
it=&sb[p];
sb.erase(it);
kill++;
}
else
break;
if (kill==k)break;
}
if (kill==k)
{
printf("%d\n",m);
break;
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator