11340 - Newspaper

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

Moderator: Board moderators

Post Reply
H_Hima
New poster
Posts: 18
Joined: Mon Sep 25, 2006 10:56 am
Location: Solar System
Contact:

11340 - Newspaper

Post by H_Hima »

what the trick in this Problem.

this is my code in the contest?
I'm aware of space char and the final value too.
and got the res in long long.

I'm completely confused...

Code: Select all

woooooowh
what a great trick.
Got acc after that.

Thanks alot
Last edited by H_Hima on Mon Nov 12, 2007 8:45 am, edited 2 times in total.
Robert Gerbicz
Experienced poster
Posts: 196
Joined: Wed May 02, 2007 10:12 pm
Location: Hungary, Pest county, Halasztelek
Contact:

Post by Robert Gerbicz »

My c code is similar to your approach. I don't know the trick but it should be really crazy. On the contest: there were 384 submissions for this problem but only 45 AC.
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

Finally figured out the trick after 20 few submissions..

Character code has range 0 ~ 255, so use unsigned char.
(Is the spoiler ? :wink:)
----
Rio
armansuleimenov
New poster
Posts: 15
Joined: Tue Sep 25, 2007 3:07 am
Location: Astana, Kazakhstan
Contact:

Post by armansuleimenov »

I used stl map, got TLE, now switched to simple hash table, got WA 3 times. what is wrong with my code?

Code: Select all

thanx all, got AC
Last edited by armansuleimenov on Tue Nov 13, 2007 6:05 am, edited 1 time in total.
Robert Gerbicz
Experienced poster
Posts: 196
Joined: Wed May 02, 2007 10:12 pm
Location: Hungary, Pest county, Halasztelek
Contact:

Post by Robert Gerbicz »

rio wrote: Character code has range 0 ~ 255, so use unsigned char.
(Is the spoiler ? :wink:)
----
Rio
Thanks, that was my problem! Now got AC.
saman_saadi
New poster
Posts: 31
Joined: Sun Feb 25, 2007 6:33 pm
Location: Tehran

Post by saman_saadi »

armansuleimenov wrote:I used stl map, got TLE, now switched to simple hash table, got WA 3 times. what is wrong with my code?
According to rio's statement:
rio wrote: Finally figured out the trick after 20 few submissions..

Character code has range 0 ~ 255, so use unsigned char.
Then you can't use string because:
typedef basic_string<char> string;
so each element of string is char (not unsigned char) and you must handle this.
armansuleimenov
New poster
Posts: 15
Joined: Tue Sep 25, 2007 3:07 am
Location: Astana, Kazakhstan
Contact:

Post by armansuleimenov »

so each element of string is char (not unsigned char) and you must handle this.
What input routine should I use then?

I can't use the code below since the character can be whitespace (' '):

Code: Select all

ll cost;
unsigned char ch;
cin>>ch>>cost;
cnt[(int)ch]=cost;
armansuleimenov
New poster
Posts: 15
Joined: Tue Sep 25, 2007 3:07 am
Location: Astana, Kazakhstan
Contact:

Post by armansuleimenov »

should I use 64-bit integer to store the value of cents?
baodog
Experienced poster
Posts: 202
Joined: Wed Jul 04, 2007 6:53 am

Easy Fix

Post by baodog »

Yes, you can read in char !! It just may be negative.

Simply add a constant !!! (128 or bigger)

Please, remove your code as good etiquette if you get ac.
saman_saadi
New poster
Posts: 31
Joined: Sun Feb 25, 2007 6:33 pm
Location: Tehran

Re: Easy Fix

Post by saman_saadi »

baodog wrote:Yes, you can read in char !! It just may be negative.

Simply add a constant !!! (128 or bigger)

Please, remove your code as good etiquette if you get ac.
In the contest time they release a clarification:
Solution for each test case must be printed on a separate line.
I.e.
Code:
10.10$
10.11$


Each character value is non-negative and at most 1000 cents worth.
According to the clarification character value is non-negative but I didn't see any statement about the range of characters in the problem. I got AC with unsigned char and don't handle negative characters. Are you sure there are negative characters in the input? If input has negative characters and the range of characters is -128 <= x <= 127 then I got AC in the contest time! After the contest I only change char to unsigned char (according to rio's statement) and got AC.

We know the range of char is:
-128 <= x <= 127
You say we must add a value 128 or higher to char so we have:
0 <= x + 128 <= 255
It's obvious 255 can't fit on char and it fit on unsigned char.[/code]
Last edited by saman_saadi on Mon Nov 12, 2007 9:55 am, edited 3 times in total.
saman_saadi
New poster
Posts: 31
Joined: Sun Feb 25, 2007 6:33 pm
Location: Tehran

Post by saman_saadi »

armansuleimenov wrote: What input routine should I use then?

I can't use the code below since the character can be whitespace (' '):
You can use cin.get() method:

Code: Select all


unsigned char ch = cin.get();

But you must notice cin.get() reads white spaces ('\t', '\r', '\n', ' ') and don't ignore them so you must be careful And according to clarification you can't use int for storing characters values.
Last edited by saman_saadi on Mon Nov 12, 2007 9:35 am, edited 1 time in total.
Hojjat jafary
New poster
Posts: 10
Joined: Sun Sep 16, 2007 9:35 am

Re

Post by Hojjat jafary »

char ch = 255;
ch is negative one !
but the clarification said that the character codes are non-negative.
then you can use only char.
darkos32
New poster
Posts: 27
Joined: Tue Jul 25, 2006 8:10 am
Location: Indonesia
Contact:

asd

Post by darkos32 »

how to used cin.get() ?
i used like this for input :

2
av
sd

Code: Select all


scanf("%d\n",&m);
long total = 0;
while(m--){
unsigned char ch;
ch = cin.get();
cout << ch;
int cht = (int) ch;
}

but it prints nothing..and how to check the newline ?

thanks.
saman_saadi
New poster
Posts: 31
Joined: Sun Feb 25, 2007 6:33 pm
Location: Tehran

Re: asd

Post by saman_saadi »

darkos32 wrote:how to used cin.get() ?
i used like this for input :

2
av
sd

Code: Select all


scanf("%d\n",&m);
long total = 0;
while(m--){
unsigned char ch;
ch = cin.get();
cout << ch;
int cht = (int) ch;
}

but it prints nothing..and how to check the newline ?

thanks.
I think you must use cin instead of scanf because cin buffer and scanf buffer are different.
input:

2
av
sd

Code: Select all

	int n, ch1, ch2;

	for (cin >> n; n--;)
	{
		cin.get();	//feeding new line character in cin >> n
		ch1 = cin.get();
		ch2 = cin.get();
		cout << (unsigned char)ch1 << (unsigned char)ch2 << endl;
	}
for checking new line character using below code:

Code: Select all

ch = cin.get();
if (ch == '\n')
{
.
.
.
}
but I think it's better to write:

Code: Select all

if (ch == '\n' || ch == '\r')
I change unsigned char to int (because cin.get() return int) and submit it again and I found that no negative character exist in input data.[/code]
Hojjat jafary
New poster
Posts: 10
Joined: Sun Sep 16, 2007 9:35 am

Post by Hojjat jafary »

another way is use gets( str_buff ) and use sscanf()
and cin.get( char );
Post Reply

Return to “Volume 113 (11300-11399)”