Analysis
这题要证明一个结论,答案就是所有的 (a0*i mod n,b0*i mod n) i=0..n-1,证明在草稿纸上懒得打出来……应当不难吧。
Accepted Code
type
lintpair=array[1..2] of longint;
var
tot,n,i,a,b,x,y:longint;
ans:array[1..20000] of lintpair;
function comp(a,b:lintpair):boolean;
begin
if a[1]=b[1] then
comp:=a[2]<b[2]
else
comp:=a[1]<b[1];
end;
procedure sort(l,r:longint);
var
i,j:longint;
mid,tmp:lintpair;
begin
i:=l;
j:=r;
mid:=ans[(i+j) shr 1];
repeat
while comp(ans[i],mid) do
inc(i);
while comp(mid,ans[j]) do
dec(j);
if not (i>j) then
begin
tmp:=ans[i];
ans[i]:=ans[j];
ans[j]:=tmp;
inc(i);
dec(j);
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
read(n,a,b);
a:=a mod n;
b:=b mod n;
tot:=1;
x:=a;
y:=b;
repeat
x:=(x+a) mod n;
y:=(y+b) mod n;
ans[tot][1]:=x;
ans[tot][2]:=y;
inc(tot);
until (x=a) and (y=b);
dec(tot);
writeln(tot);
sort(1,tot);
for i:=1 to tot do
writeln(ans[i][1],' ',ans[i][2]);
end.
本文介绍了一种解决模运算周期性问题的方法,并通过具体的编程实现验证了该方法的有效性。采用递推的方式生成模运算序列,并使用快速排序算法进行排序。

575

被折叠的 条评论
为什么被折叠?



