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 1000. A+B Problem

Pages: Previous 1 2 3 Next
Re: Or using ':=' operator only :)
Posted by Roma Labish[Lviv NU] 10 Jan 2007 15:49
So what? you can't see  '+' in program => there isn't '+' :)

inc(b,a) -> I didn't know it, becouse I'm C++ programmer :)
Re: 106 )
Posted by Slam [Tartu U] 11 Jan 2007 07:41
RockBeat wrote 9 January 2007 00:30
#include<iostream.h>

main(){
    int x,y,i; <--- LOL :)
    for(cin>>x>>y,x=~x;x^~0;x^=y^=x^=y)
        for(y^=i=1;y&i;y^=i<<=1);
    cout<<~y;
}

Edited by author 09.01.2007 01:03
Re: Pascal forever!)
Posted by KIRILL(ArcSTU) 15 Jan 2007 14:32
Assembler solutions are cheating, but about this one ;)

type pinteger = ^integer;
var a, b: integer;
       p:procedure;
   instr:array [1..11] of byte =   ($8B, $45, $08, $8B, $55, $0C, $8B, $12, $01, $10, $C3);

procedure sum(a, b: pinteger); stdcall;
begin
  p();
end;

begin
  p:=@instr;
  readln(a, b);
  sum(@a, @b);
  writeln(a);
end.

It's not forbidden by any rules
It may be done more simplify, but I had many troubles
to get AC with FreePascal on Timus
Re: Pascal forever!)
Posted by Lomir 1 Apr 2007 23:26
Here is my solution without + :)
However it will be shorter in pascal...
#include <cstdio>
int main ()
{
    int a; int b;
    scanf("%d %d", &a, &b);
    __asm{
        mov eax, dword ptr a
        add eax, dword ptr b
        mov dword ptr a, eax
    }
    printf("%d\n", a);
    return 0;
}

Edited by author 01.04.2007 23:27
Re: Pascal forever!)
Posted by PSV 2 Apr 2007 02:40
 KIRILL(ArcSTU) ----------> COOL
Re: Pascal forever!)
Posted by rumi 28 Apr 2007 00:37
begin
randomize;
write(300-199*random(2))
end.
Re: Pascal forever!)
Posted by Alias (Alexander Prudaev) 5 May 2007 23:10
#include <stdio.h>

int main()
{
    char m[1];
    int a,b;
    scanf("%d %d", &a, &b);
    printf("%d\n", &b[&m[a]]-m);
    return 0;
}

of course it must be &((&m[a])[b])-m;

Edited by author 05.05.2007 23:12
C++ forever
Posted by Alias (Alexander Prudaev) 6 May 2007 14:34
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d", &a, &b);
    printf("%d\n", &b[&((char*)0)[a]]);
    return 0;
}

 after compile :
 mov    eax, DWORD PTR _a$[ebp]
 add    eax, DWORD PTR _b$[ebp]
Re: Or using ':=' operator only :)
Posted by And IV 22 Jun 2007 17:16
rules on olimpiads: dont use assembler, but it works on timus. :)

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
a,b:integer;
begin
readln(a,b);
asm
mov eax,a;
add eax,b;
mov a,eax;
end;
writeln(a);
end.

Edited by author 22.06.2007 17:20
Re: Pascal forever!)
Posted by Mansurov Artur 16 Jul 2008 22:30
KIRILL(ArcSTU) ----------> COOL
+1
Re: Pascal forever!)
Posted by OpenGL 13 Oct 2008 19:06
program qwerty;
var a,b:integer;
begin
read(a,b);
if(a=b)then a:=a shl 1
else a:=(sqr(a)-sqr(b))div(a-b);
write(a);
end.
Re: Pascal forever!)
Posted by penartur 13 Oct 2008 23:18
2OpenGL: As it stated on previous page, you cannot use the '-' sign (otherwise, the task would have been extremely simple, you could write just "return a--b" or something like this).
--
C#:

using System;

namespace Task1000b {
    class Program {

        private static int Sum(int a, int b) {
            if(a == 0) {
                return b;
            } else if(b == 0) {
                return a;
            } else {
                return Sum(a^b, (a&b)<<1);
            }
        }

        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split();
            Console.WriteLine(Sum(int.Parse(input[0]), int.Parse(input[1])));
        }
    }
}

Edited by author 13.10.2008 23:18
Re: Pascal forever!)
Posted by penartur 13 Oct 2008 23:55
Or, shortened:
using System;
namespace n {
    class c {
        static void Main() {
            string[] i = Console.ReadLine().Split();
            int a = int.Parse(i[0]);
            int b = int.Parse(i[1]);
            while((a&b)!=0) {
                a = a^b;
                b = (b&~a)<<1;
            }
            Console.WriteLine(a^b);
        }
    }
}
Re: Pascal forever!)
Posted by Anisimov Dmitry (Novosibirsk STU) 6 Nov 2008 01:18
#include <stdio.h>
#include <string.h>

char a[1024000];
char b[1024000];
int x,y;

int main() {
    scanf("%d %d",&x,&y);
    while(x>strlen(a)) strcat(a," ");
    while(y>strlen(b)) strcat(b," ");
    strcat(a,b);
    printf("%d\n",strlen(a));
    return 0;
}
C
Posted by Anisimov Dmitry (Novosibirsk STU) 6 Nov 2008 01:20
#include <stdio.h>

int x,y;

int main() {
      scanf("%d%d",&x,&y);
      fseek(stdin,x,SEEK_SET);
      fseek(stdin,y,SEEK_CUR);
    printf("%d\n",ftell(stdin));
    return 0;
}

Edited by author 06.11.2008 01:22

Edited by author 06.11.2008 01:23
Re: C
Posted by Anisimov Dmitry (Novosibirsk STU) 6 Nov 2008 01:32
#include <cstdio>

int x,y;

int main() {
      scanf("%d%d",&x,&y);
    printf("%d\n",&(&((char*)0)[x])[y]);
    return 0;
}
Re: Or using bitwise operations only :)
Posted by wangling219 22 Nov 2008 20:13
Great|!
Re: can you solve this, without using "+"? :)
Posted by mingyuangao 23 Nov 2008 17:21
For Pascal, it is easy.
Just use the procedure "inc".
Fast Fourier Transofmation Solution :)
Posted by Alias aka Alexander Prudaev 20 Mar 2009 08:29
#include <complex>
typedef complex<double> com;

const double Pi = acos(-1.0);

void FastFourierTransformation(vector<com> &a, int z)
{
    if (a.size() == 1) return;
    vector<com> a0;
    vector<com> a1;
    for (int i = 0; i < a.size(); i++)
        if (i & 1)
            a1.push_back(a[i]);
        else
            a0.push_back(a[i]);
    FastFourierTransformation(a0, z);
    FastFourierTransformation(a1, z);
    com x = com(cos(z * 2 * Pi / a.size()), sin(z * 2 * Pi / a.size()));
    com xx(1);
    for (int i = 0; i < a.size() / 2; i++)
    {
        a[i] = a0[i] + a1[i] * xx;
        a[i + a.size() / 2] = a0[i] - a1[i] * xx;
        xx = xx * x;
    }
}

int main()
{
    int A, B;
    scanf("%d %d", &A, &B);
    vector<com> a(4, com(0));
    a[0] = com(A);
    a[1] = com(B);
    FastFourierTransformation(a, 1);
    int ans = (int)(a[0].real() + 0.5);
    printf("%d\n", ans);
    return 0;
}

Edited by author 20.03.2009 15:51
Re: can you solve this, without using "+"? :)
Posted by blacksnow 29 Apr 2009 19:51
WELL DONE!!!
Pages: Previous 1 2 3 Next