题目:https://jzoj.net/senior/#main/show/1433
这套比赛因为当时做的太差,所以这道刚刚一眼看出的题目也写一下吧。
完全不知道为什么当时我这题会爆0?
k<=1000,很明显的暴力也能过啊。
对于第i个数,如果知道了它的坐标,答案显然。
那么对于第i个数,我们就拿它去更新其它的与它同一行的,更新完同一行之后再更新同一列,就可以啦~
代码:
var
x,r,c,xx,yy,t:array[1..1000] of longint;
n,k,i,j,ans1,ans2:longint;
begin
readln(n,k);
for i:=1 to k do
begin
readln(x[i],r[i],c[i]);
xx[i]:=(x[i]-1) div n+1;
yy[i]:=(x[i]-1) mod n+1;
end;
for i:=1 to k do
begin
if yy[i]>c[i] then ans1:=c[i]+n-yy[i] else ans1:=c[i]-yy[i];
if xx[i]>r[i] then ans2:=r[i]+n-xx[i] else ans2:=r[i]-xx[i];
writeln(ans1+ans2);
for j:=i+1 to k do
if xx[j]=xx[i] then yy[j]:=(yy[j]+ans1-1) mod n+1;
for j:=i+1 to k do
if yy[j]=c[i] then xx[j]:=(xx[j]+ans2-1) mod n+1;
end;
end.
难度:**