10079 - Pizza Cutting

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion » Fri Feb 14, 2003 6:36 am

Just declare the variable as:
long long a;

sample:
int main() {
..long long a;
..a = 22345672948472475823;
.. printf ("%lld\n", a);
}

*for scanf and printf use the flag "%lld" *
Just that,

Good Luck! :lol:

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

Re

Post by Sajid » Fri Feb 21, 2003 8:15 pm

[c]long long a;
...
printf("%lld",...);[/c]

Is this both in the ANSI C ? plz, eXplain more.
Sajid Online: www.sajidonline.com

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal » Mon Feb 24, 2003 8:32 pm

Its better to solve by a simple math law of High
school which u used to make
1+2+3+4+.....+n
just add 1 more to it.


Yes sajid that lld works with Turbo C
but not with borland C++

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam » Thu Feb 27, 2003 11:28 pm

i think lld works in only linux and unix platform..
turbo c uses it but don't store actual amount of data that gcc store in linux..
:oops: :oops: :oops:
"Everything should be made simple, but not always simpler"

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Fri Feb 28, 2003 9:22 am

anupam - you have right....

In C/C++ I use something like this (for 64 bit integer, I use MS VC++ as main compiler at home):

Code: Select all

#ifdef ONLINE_JUDGE /* parts for OJ system check */
#define LONG long long int
#define L_IN  "%lld"
#else /* Windows VC++ part */
#define LONG __int64
#define L_IN  "%I64d"
#endif

LONG a;

scanf(L_IN,&a);
printf(L_IN,a);
and it's work great. you could create more definitions i.e. for unsigned or other data type. BTW the same efect give you if you use typedef in C/C++ instead of #define as I

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

10079

Post by Eduard » Mon Dec 01, 2003 9:29 pm

it gives WA help pleas
[pascal]program acm10079;
label 1;
var i,n:longint;
sum:comp;
begin
repeat
read(n);
if n<0 then goto 1;
sum:=n*n;
sum:=sum+n;
sum:=sum/2;
sum:=sum+1;
if n=0 then writeln(0) else writeln(round(sum));
until 1=2;
1:
end.
[/pascal]
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

User avatar
Russell John
New poster
Posts: 40
Joined: Mon Jul 21, 2003 9:21 am
Location: Planet Earth
Contact:

Post by Russell John » Tue Dec 02, 2003 11:06 am

Your algorithm is inefficient.
1024 Programmer's Lane,
Algorithm City, United States of C++,
Planet Earth.

Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

Post by Eduard » Tue Dec 02, 2003 12:56 pm

what you mean my algorithm is correct yes? then...?Or no...?
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650

osan
New poster
Posts: 47
Joined: Tue Jul 29, 2003 12:03 pm
Location: Bangladesh,Dhaka.
Contact:

i think u can make more simple the algorithm

Post by osan » Wed Dec 17, 2003 6:22 pm

any way u have to hold the result in long long or long double. coz it can be bigger than long range.

long double %Lf
long long %lld

result= (n-1)result+n
found the simple equation from that.
anyway if u can't then mail me. i will help u.
this time WA
what next...............?

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

10079 WA...Why

Post by midra » Fri May 14, 2004 3:50 am

First of all sorry for my bad english.
I think my formulas are right.
I I used this logic...
With every new line, the way that maximize the number of parts is that the new line pass over all the older lines, so with every new line you have n lines more, I mean, the line number five will add 5 more parts, for line 6 the pizza will have 6 more parts that when it has 5 lines, etc, etc...
From there I get the formulas but I get WA...

Here is my code:

[c]
CODE REMOVED
if somebody need help with this problem send me a PM
[/c]

If somebody knows why is wrong...please tell me.
Last edited by midra on Thu May 20, 2004 1:18 am, edited 1 time in total.

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

HI

Post by sumankar » Fri May 14, 2004 4:54 am

SIGSEGV is mainly due to invalid memory reference,
such as when you are trying to access invalid memory locs and/or
restricted mem-locs.

As for your program I can only suggest, provided your formula is correct :wink:
to change
[c]
while(scanf("%ld",&temp)!=EOF)
[/c]
to something like
[c]
while(scanf("%ld",&temp) == 1)
[/c]
that takes care of a missing EOF and other weird end-of-file stuff :-?
hth
Suman

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra » Sat May 15, 2004 1:28 am

Thank you 'Again' sumankar. :wink:
I have changed but I still got WA.... It never says SIGSEGV or an error like that, I always get WA...
I think maybe the type double is the problem, but I don't know...

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

WA etc

Post by sumankar » Sat May 15, 2004 7:56 pm

two things I'd like to add:
1)no need for double(i.e float-point arithmetic)

2)check your formula

There's a very thin line between helping and spoiling a problem,
for further help PM me/search the net.

hth
Suman

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

WA etc

Post by sumankar » Sat May 15, 2004 7:59 pm

two things I'd like to add:
1)no need for double(i.e float-point arithmetic)

2)check your formula

There's a very thin line between helping and spoiling a problem,
for further help PM me/search the net.

hth
Suman

mhayter1
New poster
Posts: 15
Joined: Wed Jul 26, 2006 10:00 am

Unusual

Post by mhayter1 » Sat Aug 12, 2006 3:23 am

On the problem cutting pizza. This works:

Code: Select all

cout<<((n*(n+1))/2)+1<<endl;
but this doesn't

Code: Select all

cout<<n*n*.5+n*.5+1<<endl;
you must change it to this:

Code: Select all

cout<<(long long)n*n*.5+n*.5+1<<endl;
does anyone know why this is?

Post Reply

Return to “Volume 100 (10000-10099)”