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

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

Страницы: 1 2 3 Следующая
can you solve this, without using "+"? :)
Послано Alexander Prudaev 27 окт 2006 00:26
can you solve this, without using "+"? :)
Re: can you solve this, without using "+"? :)
Послано Krayev Alexey (PSU) 27 окт 2006 02:58
-(-a-b)
Re: can you solve this, without using "+"? :)
Послано Nurbek 21 дек 2006 23:30
-(-a-b)
BRAVO !!! :)

Edited by author 21.12.2006 23:31
Re: can you solve this, without using "+"? :)
Послано KIRILL(ArcSTU) 22 дек 2006 19:00
a--b
a------------------------b  :)))
I can do it without using + and - :-)
Послано Ostap Korkuna (Lviv NU) 23 дек 2006 01:43
#include <stdio.h>
#include <math.h>

void main()
{
double a, b;
scanf("%lf%lf", &a, &b);
double c = log(exp(a)*exp(b));
printf("%.0lf", c);
}
Of course!!!
Послано [SSAU_#617]snipious aka Pimenov Sergey Nikolaevich 8 янв 2007 17:42
var
  a, b: integer;
begin
  read(a, b);
  asm
    mov ax, a;
    add ax, b;
    mov a, ax;
  end;
  writeln(a);
end.
Or using bitwise operations only :)
Послано it4.kp 8 янв 2007 22:13
#include <iostream>

using namespace std;

int sum(int a, int b){
    return (!a||!b ? a|b : sum((a&b)<<1,a^b));
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << sum(a,b);
    return 0;
}
Re: Or using bitwise operations only :)
Послано Roma Labish[Lviv NU] 8 янв 2007 22:16
You stole my Idea :) I just think about it, but you write it faster then me :).

Edited by author 08.01.2007 22:17
Re: Or using bitwise operations only :)
Послано it4.kp 8 янв 2007 22:26
Ok, let's make problem more interesting...
What is the shortest program to add A and B?

Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden

My very raw variant's length is 129:

#include <iostream>

int s(int a, int b){
return (!a||!b ? a|b : s((a&b)<<1,a^b));
}

int main(){
int a, b;
std::cin >> a >> b;
std::cout << s(a,b);
return 0;
}

Edited by author 08.01.2007 22:40
119 )
Послано RockBeat 8 янв 2007 23:33
#include<iostream.h>

#define _(x,y)    for(i=1;x&i;y^=i,i<<=1);y^=i;

main(){
    int x,y,i;
    for(cin>>x>>y;y;){_(x,x)_(~y,y)}
    cout<<x;
}
108 )
Послано it4.kp 8 янв 2007 23:48
#include <iostream.h>

int s(int a, int b){
return !a||!b ? a|b : s((a&b)<<1,a^b);
}

main(){
int a, b;
cin >> a >> b;
cout << s(a,b);
}

Edited by author 09.01.2007 00:14
106 )
Послано RockBeat 9 янв 2007 00:30
#include<iostream.h>

main(){
    int x,y,i;
    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: Or using bitwise operations only :)
But with ASM it'll run more quickly!!!
Re: can you solve this, without using "+"? :)
Послано KIRILL(ArcSTU) 9 янв 2007 00:40
I've solved it on pascal some time ago, but not post
It's not short of course :)


var
  i,a,b,s,c:integer;
begin
  read(a,b);
  for i:=0 to 31 do
  begin
    s:=s or (a and 1 xor b and 1 xor c) shl i;
    c:=(c and (a and 1 xor b and 1)) or (a and 1 and b and 1);
    a:=a shr 1;
    b:=b shr 1
  end;
 write(s)
end.
Re: Or using bitwise operations only :)
Послано KIRILL(ArcSTU) 9 янв 2007 00:42
[SSAU_#617]snipious_#1 aka Pimenov Sergey Nikolaevich писал(a) 9 января 2007 00:35
But with ASM it'll run more quickly!!!
Compiler generates better assembler code
for a:=a+b than your one
Re: Or using bitwise operations only :)
And what is it??? Try to use 10^10 my code and c:=a+b;!!!
No subject
Послано Metallllllll 10 янв 2007 02:01


Edited by author 10.01.2007 02:09
Or using ':=' operator only :)
Послано Roma Labish[Lviv NU] 10 янв 2007 02:10
Without :
it4.kp писал(a) 8 января 2007 22:26
Ok, let's make problem more interesting...
What is the shortest program to add A and B?

Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden
and without bitwise operation:) :

63 symbols:

var a,b,i:integer;
begin
read(a,b);
for i:=1 to a do inc(b);
write(b)
end.
Re: Or using ':=' operator only :)
Послано KIRILL(ArcSTU) 10 янв 2007 03:07
Tests are simple. You solution pass TL easily, but

for i:=1 to a do inc(b); equal to inc(b,a);
Re: Or using ':=' operator only :)
Послано Slam [Tartu U] 10 янв 2007 03:08
inc() is using + itself so its forbidden
Страницы: 1 2 3 Следующая