ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1000. A+B Problem

Re: Or using ':=' operator only :)
Послано Roma Labish[Lviv NU] 10 янв 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 )
Послано Slam [Tartu U] 11 янв 2007 07:41
RockBeat писал(a) 9 января 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!)
Послано KIRILL(ArcSTU) 15 янв 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!)
Послано Lomir 1 апр 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!)
Послано PSV 2 апр 2007 02:40
 KIRILL(ArcSTU) ----------> COOL
Re: Pascal forever!)
Послано rumi 28 апр 2007 00:37
begin
randomize;
write(300-199*random(2))
end.
Re: Pascal forever!)
Послано Alias (Alexander Prudaev) 5 май 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
Послано Alias (Alexander Prudaev) 6 май 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 :)
Послано And IV 22 июн 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!)
Послано Mansurov Artur 16 июл 2008 22:30
KIRILL(ArcSTU) ----------> COOL
+1
Re: Pascal forever!)
Послано OpenGL 13 окт 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!)
Послано penartur 13 окт 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!)
Послано penartur 13 окт 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!)
Послано Anisimov Dmitry (Novosibirsk STU) 6 ноя 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
Послано Anisimov Dmitry (Novosibirsk STU) 6 ноя 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
Послано Anisimov Dmitry (Novosibirsk STU) 6 ноя 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 :)
Послано wangling219 22 ноя 2008 20:13
Great|!
Re: can you solve this, without using "+"? :)
Послано mingyuangao 23 ноя 2008 17:21
For Pascal, it is easy.
Just use the procedure "inc".
Fast Fourier Transofmation Solution :)
Послано Alias aka Alexander Prudaev 20 мар 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 "+"? :)
Послано blacksnow 29 апр 2009 19:51
WELL DONE!!!