惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
量子位
N
Netflix TechBlog - Medium
The Cloudflare Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
B
Blog
博客园_首页
博客园 - Franky
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
H
Help Net Security
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell

hsfzxjy 的博客

解决 VSCode + CMake + MSVC 编译器信息乱码的问题 使用 3090 部署 1.58bit 动态量化版 DeepSeek R1 671b 如何在 VS Code DevContainer 中配置 HTTP 代理 如何在跳板机背后的服务器上使用 VS Code Remote - Containers Cohesive Digests for Ints and Floats Rust 中的隐匿概念 —— Place(位置) 美术馆 一尺之槌,日取其半,1075日而竭 老生常谈:使用 Cloudflare 自选 IP 加速站点访问 辩义 State、Nation 与 Country 将 Base64 编码的数据快速转换为 Uint8Array 折腾 NPU·第1章 —— 搭建 Level Zero 开发环境 折腾 NPU·第0章 —— Intel NPU 概述与 Level-Zero 新增域名 monad.run CSS 中为特定字符设置不同字体 Arbitary Lifetime Transmutation via Rust Unsoundness Dijkstra 算法的延伸 Manacher 回文计数算法 硬卧 Go Fact: Zero-sized Field at the Rear of a Struct Has Non-zero Size Display *big.Rat Losslessly and Smartly in Golang 代码的仪式 Building Electron From Scratch 中式亲属称谓研究之一:构建半群 Some Notes on Kotlin Coroutines Git sparse-checkout and partial clones for Mega-Repos 辩义“封建” Diving from the CUDA Error 804 into a bug of libnvidia-container Modern Cryptography, GPG and Integration with Git(hub) Move the Root Partition of Ubuntu
UVa1647 Computer Transformation
2014-10-24 · via hsfzxjy 的博客

链接:Link 耗时:0.679s

分析

本质上,这是一道求数列通项的题目。我们列出前几个字符串: $$01,$$ $$1001,$$ $$01101001,$$ $$1001011001101001,$$ $$\ldots$$

如果用$S_i$表示第 i 个字符串中“00”的个数,则有: $$S_1=0,\ S_2=1,\ S_3=1,\ S_4=3,\ S_5=5,\ S_6=11,\ldots$$

经过观察可以发现有如下规律: $$S_n=2\times S_{n-1}+{(-1)}^n$$

求通项就简单了,换个元即可: $$S_n=\frac{1}{3}[{(-1)}^n+2^{n-1}]$$

程序采用高精度实现。

Code

const
JINDU = 100000;
var
n: Integer;

procedure PrintANumber(x: longint);
var
t: longint;
begin
if x = 0 then
write('00000')
else
begin
t := JINDU;
while t > x * 10 do
begin
write(0);
t := t div 10;
end;
write(x);
end;
end;

var
ans: array [1..300] of longint;
len, i: integer;

procedure calc2;
var
i, x, t, mul: longint;
begin
len := 1;
ans[1] := 1;
t := n-1;
while t > 0 do
begin
if t < 6 then
mul := 1 << t
else
mul := 64;
x := 0;
for i := 1 to len do
begin
ans[i] := ans[i] * mul + x;
x := ans[i] div JINDU;
ans[i] := ans[i] mod JINDU;
end;
if x > 0 then
begin
inc(len);
ans[len] := x;
end;
dec(t, 6);
end;
end;

procedure div3;
var
i, x, t: longint;
begin
i := len;
x := 0;
while i > 0 do
begin
t := (x * JINDU + ans[i]);
ans[i] := t div 3;
x := t mod 3;
dec(i);
end;
while ans[len] = 0 do dec(len);
end;

begin
assign(input, 'main.in'); reset(input);
assign(output, 'main.out'); rewrite(output);

while not eof do
begin
readln(n);
if n=1 then
begin
writeln(0);
continue;
end;
fillchar(ans, sizeof(ans), 0);
calc2;
if odd(n) then
dec(ans[1])
else
inc(ans[1]);
div3;
write(ans[len]);
for i := len-1 downto 1 do
PrintANumber(ans[i]);
writeln;
end;

close(input); close(output);
end.

作者:hsfzxjy
链接:
许可:CC BY-NC-ND 4.0.
著作权归作者所有。本文不允许被用作商业用途,非商业转载请注明出处。