1 条题解

  • 0
    @ 2025-2-14 20:50:07

    C++ :

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    using namespace std;
    int main()
    {
    	 int m,n,t=0,x=0;
    	 scanf("%d%d",&m,&n);
    	 int a[m+10];
    	 memset(a,0,sizeof(a));
    	 while(x!=m-1)
    	 {
    	 	for(int b=1;b<=m;++b)
    	 	{
    	 		if(a[b]==0)
    	 		{
    	 			++t;
    	 		}
    	 		if(t==n)
    	 		{
    	 			++x;
    	 			a[b]=1;
    	 			t=0;
    	 		}
    	 		if(x==m-1)
    	 		{
    	 			break;
    	 		}
    	 	}
    	 }
    	 for(int c=1;c<=m;++c)
    	 {
    	 	if(a[c]==0)
    	 	{
    	 		printf("%d",c);
    	 	}
    	 }
    	 return 0;
    }
    

    Pascal :

    var a:array[1..100] of longint;
        i,t,p,n,m:longint;
    begin
      readln(n,m);
      for i:=1 to n do a[i]:=1;
      i:=0;
      while t<n-1 do
        begin
          inc(i);
          if a[i]<>0 then inc(p);
          if p=m then 
            begin
              a[i]:=0; p:=0;
              inc(t);
            end;
          if i=n then i:=0;
        end;
      for i:=1 to n do
        if a[i]<>0 then begin writeln(i); break; end;
    end.
    
    • 1

    信息

    ID
    413
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者