bzoj2797
对和排序,显然最小是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的更多相关文章
- 【BZOJ2797】[Poi2012]Squarks 暴力乱搞
[BZOJ2797][Poi2012]Squarks Description 设有n个互不相同的正整数{X1,X2,...Xn},任取两个Xi,Xj(i≠j),能算出Xi+Xj.现在所有取法共n*(n ...
- [BZOJ2797][Poi2012]Squarks
2797: [Poi2012]Squarks Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 211 Solved: 89[Submit][Status ...
- POI2012题解
POI2012题解 这次的完整的\(17\)道题哟. [BZOJ2788][Poi2012]Festival 很显然可以差分约束建图.这里问的是变量最多有多少种不同的取值. 我们知道,在同一个强连通分 ...
随机推荐
- Careercup - Google面试题 - 4716965625069568
2014-05-06 00:17 题目链接 原题: Given a -D matrix represents the room, obstacle and guard like the followi ...
- Jenkins部署.NET网站项目
Jenkins Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 持 ...
- C# File
http://msdn.microsoft.com/zh-cn/library/system.io.file(v=vs.110).aspx using System; using System.IO; ...
- mongodb 的安装历程
mongo 安装历程 mongo的安装方法有千万种,只有一种让我觉得还不错,说说安装过程中的一点心德. 方法一:源码安装,千万别用这种方法,尼马我用虚拟机编译了一下午,竟然没有编译完,强制关机,第二天 ...
- ios 开发常用快捷键
CTRL + K 删除一行,尽量在行首处使用: CMD+ / 注释,取消注释 CMD + R 运行 CMD + . 停止运行 CMD + F 普通搜索 CMD + CTRL + ↑/↓ 切换头 ...
- Python性能分析指南
http://www.admin10000.com/document/2861.html 尽管并非每个你写的Python程序都需要严格的性能分析,但了解一下Python的生态系统中很多优秀的在你需要做 ...
- POJ 3461 Oulipo(字符串匹配,KMP算法)
题意:给出几组数据,每组有字符串W和T,问你W在T中出现几次. 思路:字符串长度很大,用KMP算法. 一开始写的是:调用KMP算法查找W在T中是否匹配,若匹配,则个数+1.则接下来T的索引移动相应的距 ...
- 【leetcode】Find Peak Element ☆
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- java基础知识回顾之java Thread类学习(七)--java多线程安全问题(死锁)
死锁:是两个或者两个以上的线程被无限的阻塞,线程之间互相等待所需资源. 线程死锁产生的条件: 当两个线程相互调用Join()方法. 当两个线程使用嵌套的同步代码块的时候,一个线程占用了另一个线程的锁, ...
- LINUX下如何查看tomcat运行状态,判断其是否启动
1,查看Tomcat启动日志. ${catalina_home}\logs [root@iZ25b4ffkfaZ logs]# tail -f catalina.outSep 10, 2015 11: ...