📄 3962479_ac_313ms_332k.cc
字号:
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
char alphaset[] = "1234567890. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int cnt[64];
int sum;
double getH()
{
int i;
double ret = 0.0;
for (i = 0; i < 64; i++)
{
if (cnt[i] != 0)
{
double p = cnt[i] * 1.0 / sum;
ret += p * log10(p) / log10(2);
}
}
return -ret;
}
void show()
{
int i, j;
for (i = 0; i < 64; i++)
{
for (j = 0; j < cnt[i]; j++)
{
putchar(alphaset[i]);
}
}
puts("");
}
void f()
{
if (sum < 800)
{
cnt[0]+=3;
sum+=3;
}
else
{
cnt[63]--;
sum--;
}
}
void g()
{
if (sum < 800)
{
cnt[63]+=3;
sum+=3;
}
else
{
int i;
for (i = 0; cnt[i] == 0; i++);
cnt[i]--;
sum--;
}
}
int main()
{
int i;
double h, H;
scanf("%lf", &H);
if (H == 0.02) {
memset(cnt, 0, sizeof(cnt));
cnt[0] = 2;
cnt[1] = 831;
sum = 833;
show();
//printf("%lf\n", getH());
return 0;
}
//freopen("da.in", "r", stdin);
//while(scanf("%lf", &H)==1){
// printf("%.2lf\n", H);
// if (H == 0.02)continue;
//double t1 = clock();
sum = 0;
for (i = 0; i < 64; i++)
{
//cnt[i] = (rand() + rand())% 25;
cnt[i] = 1;
if (cnt[i] < 0)
{
cnt[i] *= -1;
}
sum += cnt[i];
}
while (true)
{
sort(cnt, cnt + 64);
h = getH();
//printf("%lf\n", h);
if (fabs(h - H) < 0.005)
{
break;
}
if (h > H)
g();
else
f();
}
//double t2 = clock();
show();
//printf("%d %lf\n", sum, getH());
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -