ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1224. Spiral

Destiny My Solution Here: [9] // Problem 1224. Spiral 13 Nov 2002 17:22
program spiral;
var
 n,m,r:real;
begin
 readln(n,m);
 if m>=n then
  begin
   if n=1.0 then
    r:=0.0
   else
    if n=2.0 then
     r:=2.0
   else
    if frac(n/2)<>0 then
     r:=4.0*trunc(n/2)
   else
    r:=2.0*(n-1);
  end
 else
  begin
   if m=1.0 then
    r:=1.0
   else
    if m=2.0 then
     r:=3.0
   else
    if frac(m/2)<>0 then
     r:=4.0*trunc(m/2)+1.0
   else
    r:=2.0*m-1.0;
 end;
 writeln(r:0:0);
end.
Arsenal Here is my problem.I think it is better than you [5] // Problem 1224. Spiral 13 Nov 2002 18:39
const{only 49K)
 maxn=11;

var
 a:array[0..maxn]of 0..9;
 n,m:longint;
 i,j,s:integer;
 ok:boolean;

begin
 fillchar(a,sizeof(a),0);
 readln(n,m);
 ok:=false;
 if n>m then begin n:=m;ok:=true;end;
 n:=n-1;
 i:=maxn+1;
 while n<>0 do
  begin
   i:=i-1;
   a[i]:=n mod 10;
   n:=n div 10;
  end;
 if ok then j:=1 else j:=0;
 for i:=maxn downto 1 do
  begin
   s:=a[i]*2+j;
   a[i]:=s mod 10;
   j:=s div 10;
  end;
 i:=0;
 while (a[i]=0)and(i<>maxn) do i:=i+1;
 for j:=i to maxn do write(a[j]);
end.
Coldfeel just so so ... [4] // Problem 1224. Spiral 21 Nov 2002 07:28
var m,n,y:real;b:boolean;
begin
 readln(m,n);
 b:=false;
 if m>n then begin y:=m;m:=n;n:=y;b:=true end;
 if m=0 then begin writeln(0);halt;end;
 if frac(m/2)<>0 then y:=int(m/2)*4
  else y:=int((m-1)/2)*4+2;
 if b then writeln(y+1:0:0) else writeln(y:0:0);
end.
Stefan Ciobaca i think mine is better/cleaner [3] // Problem 1224. Spiral 24 Nov 2002 23:25
#include <stdio.h>
#include <math.h>

int main(void)
{
    unsigned int n, m, answer;

    scanf("%u %u", &n, &m);
    if (m >= n)
        answer = 2 * (n - 1);
    else
        answer = 2 * (m - 1) + 1;
    printf("%u\n", answer);

    return 0;
}
d340960 Re: i think mine is better/cleaner [2] // Problem 1224. Spiral 12 Nov 2008 20:37
Ok, same solution after some thinking. And it is working, just remember about huge numbers you are getting in the input

#include <iostream>
using namespace std;

int main()
{
    long long nN, nM;
    cin >> nN >> nM;
    if(nM >= nN) cout << 2*(nN-1);
    else cout << 2*(nM-1)+1;
    return 0;
}

Edited by author 12.11.2008 20:43

Edited by author 12.11.2008 20:44
isliguezze(TNU) Re: i think mine is better/cleaner [1] // Problem 1224. Spiral 17 Mar 2009 22:15
Shortest sol (C language):

main() {
  unsigned n, m;
  scanf("%u%u", &n, &m);
  printf("%u", n <= m ? 2 * n - 2 : 2 * m - 1);
}
MissYouAn Re: i think mine is better/cleaner // Problem 1224. Spiral 25 Mar 2009 07:58
#include <iostream>
using namespace std;
long long n,m;

int main()
  {
    cin>>n>>m;
    if (m>=n) cout<<2*(n-1);
         else cout<<2*(m-1)+1;
  }
Rabidstorm Re: My Solution Here: [2] // Problem 1224. Spiral 26 Mar 2009 11:56
My Solution
program Ural1224;

var
  n,m:int64;

begin
  readln(n,m);
  if n<=m then writeln(n shl 1-2)
  else writeln(m shl 1-1);
end.
Rolex01 Java solution [1] // Problem 1224. Spiral 27 Aug 2013 23:04
import java.io.*;
import java.util.*;

public class www {
    public static void main(String[] args) throws IOException{
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner(System.in);
        long n = in.nextInt();
        long m = in.nextInt();
        out.println(m>=n ? 2*n-2 : 2*m-1);
        in.close();
        out.close();
    }
}

Edited by author 27.08.2013 23:07
Ahror yoshsilarda.. // Problem 1224. Spiral 11 Nov 2013 13:42
ee  munaqa bo'mag'ur  masalaga  bosh  qotirish  shartmi?