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 很显然可以差分约束建图.这里问的是变量最多有多少种不同的取值. 我们知道,在同一个强连通分 ...
随机推荐
- Hadoop启动异常情况解决方案
1. 启动时报WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using b ...
- 工程移除CocoaPods依赖库
http://zanderzhang.gitcafe.io/2015/09/26/工程移除CocoaPods依赖库/ 点这里--->CocoaPods安装和使用教程 当我们工程安装很多第三方开源 ...
- cmd下windows批处理,获取当前系统时间,生成日志文件名
示例: rdGetRTData_log%date:~0,4%%date:~5,2%%date:~8,2%.txt 生成格式: rdGetRTData_log20151103.txt 编写Windows ...
- Codeforces Round #227 (Div. 2) E. George and Cards 线段树+set
题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 ...
- reset内容
/*reset */div,p,a,span,body,dl,dt,dd,header,footer,img,section,time,h2,em,article,h3,h4,ul,li,labe ...
- js String Trim函数
<javascript> String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,"& ...
- C编程实现2的1000次方(使程序中的n=1000即可)
#include<stdio.h> #include<malloc.h> void double_(int n) { ,j,s,jw=; p=(int *)malloc(siz ...
- linux源代码阅读笔记 linux文件系统(转)
linux文件系统: 操作系统的文件数据除了文件实际内容外,还有非常多的属性,如文件权限(rwx)与文件属性(所有者.群组.时间参数等). 文件系统通常将这两部分数据存放在不同的块.权限属性放 ...
- zju 1037 Gridland(找规律,水题)
题目链接 多写几个案例,根据数据的奇偶性,就能找到规律了 #include<stdio.h> int main() { int t,n,m; double ans; scanf(" ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...