usaco 2.3 zerosum 2008.6.21
来源:互联网 发布:网络加速器官网 编辑:程序博客网 时间:2024/06/05 21:50
usaco 2.3 zerosum 2008.6.21
{
ID:
PROG: zerosum
LANG: PASCAL
}
program p_zerosum;
const r:array[1..9]ofchar=('1','2','3','4','5','6','7','8','9');
var
ans:array[1..9000]of string;
f1,f2:text;
x,y:string;
i,n,p,l:longint;
procedure qsort(i1,j1:longint);
var
l1,r1:longint;x1,y1:string;
begin
l1:=i1;r1:=j1;
x1:=ans[(l1+r1) div 2];
repeat
while ans[l1]<x1 do inc(l1);
while ans[r1]>x1 do dec(r1);
if l1<=r1 then
begin
y1:=ans[l1];ans[l1]:=ans[r1];ans[r1]:=y1;inc(l1);dec(r1);
end;
until l1>r1;
if r1>i1 then qsort(i1,r1);
if l1<j1 then qsort(l1,j1);
end;
procedure init;
begin
assign(f1,'zerosum.in');reset(f1);
assign(f2,'zerosum.out');rewrite(f2);
read(f1,n);p:=n-1;l:=0;x:='+- ';
end;
procedure put;
var i:longint;
begin
inc(l);ans[l]:='';
fori:=1 to p do
ans[l]:=ans[l]+y[i]+r[i+1];
ans[l]:='1'+ans[l];
end;
procedure count;
vart,j:longint;
begin
if y[1]<>' ' then begin t:=1;i:=1 end
else begin
t:=12;i:=2;
end;
repeat inc(i);j:=i-1;
if (y[j]='+')and(y[i]<>' ') then inc(t,i);
if (y[j]='+')and(y[i]=' ') then begin t:=t+i*10+i+1;inc(i);end;
if (y[j]='-')and(y[i]<>' ') then dec(t,i);
if (y[j]='-')and(y[i]=' ') then begin t:=t-i*10-i-1;inc(i);end;
until i>=n;
if t=0 then put;
end;
procedure deal(k:longint);
var i:longint;
begin
if k>p then begin count;exit;end;
for i:=1 to 3 do
if (i<>3)or(y[k-1]<>' ') then
begin y[k]:=x[i];
deal(k+1);end;
end;
{------------------------main---------------------------}
begin
init;
deal(1);
qsort(1,l);
fori:=1 to l do
writeln(f2,ans[i]);
close(f1);close(f2);
end.
- usaco 2.3 zerosum 2008.6.21
- usaco 2.3 zerosum
- USACO 2.3 Zero Sum (zerosum)
- USACO zerosum DFS 1A
- 享受递归的潇洒 USACO zerosum
- zerosum
- usaco 2.3 money--强悍题解2008.6.21
- USACO 2.3
- USACO2.3.3 Zero Sum (zerosum)
- USACO2.3.3 Zero Sum (zerosum)
- usaco2.3 zerosum 表达式求值 栈
- USACO 2.3 nocows
- USACO 2.3 money
- USACO 2.3 concom
- USACO 2.3 maze1
- USACO 2.3 分析
- [usaco]2.3 Zero Sum
- usaco 2.3 prefix
- usaco 2.2 runround 2008.6.20
- 论文《Joint Cascade Face Detection and Alignment》笔记
- usaco 2.2 lamps 2008.6.20
- usaco 2.2 preface 2008.6.20
- RLO文件名欺骗
- usaco 2.3 zerosum 2008.6.21
- C/C++程序到内存分配个人总结
- const char * 和 char const * 和 char * const 区别
- MySQL查询缓存 --《高性能MySQL》读书笔记
- Dynamic Programming for Brother Du
- WordPress插件开发实例教程 - 版权插件
- shape-indexed特征
- 3. AJAX 请求与响应
- 关键点匹配算法