标签:des style blog http io os ar for sp
Description
Input
Output
Sample Input
Sample Output
Hint

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define inf 0x3fffffff
#define esp 1e-10
#define N 100
using namespace std;
int z[N], x[N], lenz, lenx;
bool judge ()
{
if(z[0] && x[0])
return 0;
for (int i = 0; i < lenx; ++i)
if (x[i] > 1 || (x[i] && x[i+1]))
return 0;
for (int i = 0; i < lenz; ++i)
if (z[i] > 1 ||(z[i] ==1 && z[i+1] == 1))
return 0;
return 1;
}
void doz (int i)
{
if (i == lenz-1)
lenz++;
int up = z[i] / 2;
z[i] = z[i] & 1;
z[i+1] += up;
if (i >= 2)
z[i-2] += up;
else
{
if (lenx < 3 - i)
lenx = 3 - i;
x[1-i] += up;
}
}
void dox (int i)
{
if (i+3 > lenx)
lenx = i + 3;
int up = x[i] / 2;
x[i] = x[i] & 1;
x[i+2] += up;
if (i == 0)
z[0] += up;
else
x[i-1] += up;
}
void qt (int n)
{
memset (z, 0, sizeof(z));
memset (x, 0, sizeof(x));
lenz = 1;
lenx = 0;
z[0] = n;
while (!judge ())
{
for (int i = lenx-1; i >= 0; --i)
{
if (i == 0 && x[i] > 0 && x[i+1] > 0)
{
int up = min (x[i], x[i+1]);
z[0] += up;
x[0] -= up;
x[1] -= up;
continue;
}
else if (x[i] > 0 && x[i+1] > 0)
{
int up = min (x[i], x[i+1]);
x[i-1] += up;
x[i+1] -= up;
x[i] -= up;
continue;
}
if (x[i] > 1)
{
dox (i);
continue;
}
}
while(x[lenx-1] == 0)
lenx--;
for (int i = 0; i < lenz; ++i)
{
if (i == 0 && z[i] > 0 && x[0] > 0)
{
if (i == lenz-1)
lenz++;
int up = min (z[i], x[0]);
z[1] += up;
z[0] -= up;
x[0] -= up;
continue;
}
else if (z[i] > 0 && z[i+1] > 0)
{
if (i+3 > lenz)
lenz = i + 3;
int up = min (z[i], z[i+1]);
z[i+2] += up;
z[i+1] -= up;
z[i] -= up;
continue;
}
if (z[i] > 1)
{
doz(i);
continue;
}
}
}
while(x[lenx-1] == 0)
lenx--;
}
int main()
{
//freopen ("test.txt", "r", stdin);
int n;
while (scanf ("%d", &n) != EOF)
{
qt (n);
for (int i = lenz - 1; i >= 0; --i)
printf ("%d", z[i]);
if (lenx > 0)
printf (".");
for (int i = 0; i < lenx; ++i)
printf ("%d", x[i]);
printf ("\n");
}
return 0;
}
ACM学习历程——HDU4814 Golden Radio Base(数学递推) (12年成都区域赛)
标签:des style blog http io os ar for sp
原文地址:http://www.cnblogs.com/andyqsmart/p/4046563.html