对和排序,显然最小是a1+a2,次小a1+a3 然后穷举哪里是a2+a3 这样a1,a2,a3就求出来了

注意a2+a3只可能是前n+1项中的一个,所以穷举这步是O(n)的

接下来我们把已经确定的数的和找到并标记,那么下一个未标记的和就是a1+新的数,然后依次递推下去即可

 var v:array[..] of boolean;
a:array[..] of longint;
b:array[..] of longint;
ans:array[..,..] of longint;
i,j,n,m,t:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r:longint);
var i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; function find(l,r,x:longint):longint;
var m:longint;
begin
while l<=r do
begin
m:=(l+r) shr ;
if a[m]=x then exit(m);
if a[m]>x then r:=m- else l:=m+;
end;
exit(-);
end; procedure check(i:longint);
var j,k,p,x,y:longint;
begin
fillchar(v,sizeof(v),false);
fillchar(b,sizeof(b),);
if (a[]+a[]-a[i]) mod <> then exit;
b[]:=(a[]+a[]-a[i]) div ;
b[]:=a[]-b[];
b[]:=a[]-b[];
v[]:=true; v[]:=true; v[i]:=true;
p:=;
for j:= to n do
begin
while (p<=m) and v[p] do inc(p);
if p>m then exit;
b[j]:=a[p]-b[];
v[p]:=true;
for k:= to j- do
begin
if b[k]>=b[j] then exit;
x:=find(,m,b[k]+b[j]);
if x=- then exit;
y:=x;
while (y>) and (a[y]=a[x]) do dec(y);
inc(y);
while (y<=m) and (a[y]=a[x]) and v[y] do inc(y);
if (y>m) or (a[y]<>a[x]) or v[y] then exit;
v[y]:=true;
end;
end;
inc(t);
ans[t]:=b;
end; begin
readln(n);
m:=(n-)*n div ;
for i:= to m do
read(a[i]);
sort(,m);
for i:= to n+ do
if a[i]<>a[i-] then check(i);
writeln(t);
for i:= to t do
begin
for j:= to n do
write(ans[i,j],' ');
writeln;
end;
end.

bzoj2797的更多相关文章

  1. 【BZOJ2797】[Poi2012]Squarks 暴力乱搞

    [BZOJ2797][Poi2012]Squarks Description 设有n个互不相同的正整数{X1,X2,...Xn},任取两个Xi,Xj(i≠j),能算出Xi+Xj.现在所有取法共n*(n ...

  2. [BZOJ2797][Poi2012]Squarks

    2797: [Poi2012]Squarks Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 211  Solved: 89[Submit][Status ...

  3. POI2012题解

    POI2012题解 这次的完整的\(17\)道题哟. [BZOJ2788][Poi2012]Festival 很显然可以差分约束建图.这里问的是变量最多有多少种不同的取值. 我们知道,在同一个强连通分 ...

随机推荐

  1. 7zip 命令行

    转自 http://www.cnblogs.com/langlang/archive/2010/12/01/1893866.html 7z.exe 是 7-Zip 的命令行版本.7z.exe 使用 7 ...

  2. php缓存

    APC缓存退出舞台,APCU诞生,OPCACHE升级! 对于php5.5以后的新版本开发,使用apc习惯的开发者可能会发现php.5.5以后找不到了这个组件的更新,尤其是中文phper都找不到合适的资 ...

  3. 【BZOJ】【3158】千钧一发

    网络流/最小割 这题跟BZOJ 3275限制条件是一样的= =所以可以用相同的方法去做……只要把边的容量从a[i]改成b[i]就行了- (果然不加当前弧优化要略快一点) /************** ...

  4. Window 2008 R2 + IIS7.5 + VS2013 错误代码 0x80070002

    HTTP 错误 404.0 - Not Found 您要找的资源已被删除.已更名或暂时不可用.详细错误信息模块 IIS Web Core通知 MapRequest Handler处理程序 Static ...

  5. PV操作,

    P操作是先做减一操作,然后判读是否大于等于0. V操作是先做加一操作,然后判断是否大于0

  6. log4j 总结 精华

    去年这个时候,为做软件工程的大作业就详细学过Log4J的用法了,时隔一年想要在新的项目中好好使用一下的时候,发现几乎全忘了,悲催啊…… 再上网查资料,总是不能找到一篇符合我的口味,拿来就能轻松上手,方 ...

  7. 解决unity3d发布的网页游戏放到服务器上无法使用的问题

    http://www.unity蛮牛.com/blog-2429-1226.html 第一次把unity3d发布的网页游戏放到服务器上(Win2003),发现无法使用.可以尝试以下办法.       ...

  8. Spring @ Component 的作用

    1.@controller 控制器(注入服务) 2.@service 服务(注入dao) 3.@repository dao(实现dao访问) 4.@component (把普通pojo实例化到spr ...

  9. hdu 1370 Biorhythms

    中国剩余定理……. 链接http://acm.hdu.edu.cn/showproblem.php?pid=1370 /**************************************** ...

  10. 匿名用户访问sharepoint2010中的列表

    Allow anonymous users to access listitems on a publishing site in SharePoint 2010 https://knowledge. ...