10176 - Ocean Deep ! - Make it shallow !!
Moderator: Board moderators
10176 - Ocean Deep ! - Make it shallow !!
Can anyone tell me how to solve this problem?
i use that method but got WA. what's wrong with my code?
[pascal]
var
ch : char;
x : longint;
a : array[-17..10000]of shortint;
b : array[0..1, 1..600]of shortint;
l, lb, ll, i : longint;
p, q : integer;
p0, p1 : integer;
begin
l := 0;
while not eof do
begin
read(ch);
x := 0;
l := 0;
while ch <> '#' do
begin
if (ch = '0') or (ch = '1') then
begin
inc(l);
a[l] := ord(ch) - 48;
end;
read(ch);
end;
readln;
p0 := 0; p1 := 1;
lb := 17;
fillchar(b[p0], sizeof(b[p0]), 0);
while l > 0 do
begin
q := 0;
for i := 1 to 17 do
begin
b[p0, i] := b[p0, i] + a[l - i + 1] + q;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
i := 17;
while q > 0 do
begin
inc(i);
b[p0, i] := b[p0, i] + q mod 2;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
if i > lb then lb := i;
dec(l, 17);
end;
while (b[p0, lb] = 0) and (lb > 1) do dec(lb);
l := lb;
while true do
begin
if (l <= 17) then break;
lb := 17;
fillchar(b[p1], sizeof(b[p1]), 0);
ll := l;
l := 0;
while l <= ll do
begin
q := 0;
for i := 1 to 17 do
begin
b[p1, i] := b[p1, i] + b[p0, l + i] + q;
q := b[p1, i] div 2;
b[p1, i] := b[p1, i] mod 2;
end;
i := 17;
while q > 0 do
begin
inc(i);
b[p0, i] := b[p0, i] + q mod 2;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
if i > lb then lb := i;
inc(l, 17);
end;
while (b[p1, lb] = 0) and (lb > 1) do dec(lb);
l := lb;
p0 := p1;
p1 := 1 - p1;
end;
if l = 1 then
if b[p0, 1] = 0 then
writeln('YES')
else
writeln('NO')
else
if l = 17 then
begin
p := 1;
for i := 1 to 17 do
if b[p0, i] = 0 then
begin p := 0; break; end;
if p = 1 then writeln('YES') else writeln('NO');
end
else writeln('NO');
end;
end.
[/pascal]
[pascal]
var
ch : char;
x : longint;
a : array[-17..10000]of shortint;
b : array[0..1, 1..600]of shortint;
l, lb, ll, i : longint;
p, q : integer;
p0, p1 : integer;
begin
l := 0;
while not eof do
begin
read(ch);
x := 0;
l := 0;
while ch <> '#' do
begin
if (ch = '0') or (ch = '1') then
begin
inc(l);
a[l] := ord(ch) - 48;
end;
read(ch);
end;
readln;
p0 := 0; p1 := 1;
lb := 17;
fillchar(b[p0], sizeof(b[p0]), 0);
while l > 0 do
begin
q := 0;
for i := 1 to 17 do
begin
b[p0, i] := b[p0, i] + a[l - i + 1] + q;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
i := 17;
while q > 0 do
begin
inc(i);
b[p0, i] := b[p0, i] + q mod 2;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
if i > lb then lb := i;
dec(l, 17);
end;
while (b[p0, lb] = 0) and (lb > 1) do dec(lb);
l := lb;
while true do
begin
if (l <= 17) then break;
lb := 17;
fillchar(b[p1], sizeof(b[p1]), 0);
ll := l;
l := 0;
while l <= ll do
begin
q := 0;
for i := 1 to 17 do
begin
b[p1, i] := b[p1, i] + b[p0, l + i] + q;
q := b[p1, i] div 2;
b[p1, i] := b[p1, i] mod 2;
end;
i := 17;
while q > 0 do
begin
inc(i);
b[p0, i] := b[p0, i] + q mod 2;
q := b[p0, i] div 2;
b[p0, i] := b[p0, i] mod 2;
end;
if i > lb then lb := i;
inc(l, 17);
end;
while (b[p1, lb] = 0) and (lb > 1) do dec(lb);
l := lb;
p0 := p1;
p1 := 1 - p1;
end;
if l = 1 then
if b[p0, 1] = 0 then
writeln('YES')
else
writeln('NO')
else
if l = 17 then
begin
p := 1;
for i := 1 to 17 do
if b[p0, i] = 0 then
begin p := 0; break; end;
if p = 1 then writeln('YES') else writeln('NO');
end
else writeln('NO');
end;
end.
[/pascal]
i try with this..
but get WA, any idea?
Code: Select all
count = "number of 1's in a line";
if (count%17==0) cout << "YES" << endl;
else cout << "NO" << endl;
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
10176 WA???
please help me ,thanx;
[cpp]
#include <iostream>
using namespace std;
#include <cmath>
#include <cstdio>
#include <cstring>
int main()
{
int s;
int b=2;
char c;
int p=131071;
while(cin.get(c))
{
s=0;
do
{
if(c=='1'||c=='0')
{
s *= b;
s += int(c)-48;
s %= p;
}
}while(cin.get(c)&&c!='#');
if(s==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
[/cpp]
[cpp]
#include <iostream>
using namespace std;
#include <cmath>
#include <cstdio>
#include <cstring>
int main()
{
int s;
int b=2;
char c;
int p=131071;
while(cin.get(c))
{
s=0;
do
{
if(c=='1'||c=='0')
{
s *= b;
s += int(c)-48;
s %= p;
}
}while(cin.get(c)&&c!='#');
if(s==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
[/cpp]
10176
I got a WA in "10176"...and I have tried a lot of test data...but...I still don't know where the wrong was~~
Can someone help???
Can someone help???
Code: Select all
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned int ans,n;
char c;
while(scanf("%c",&c)!=EOF)
{
ans=0;
while(c!='#')
{
n=c-48;
n=2*ans+n;
ans=n%131071;
scanf("%c",&c);
}
scanf("%c",&c);
if(ans==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
I compiled and ran your program.
Your algorithm is OK but your program always prints
and additional unnecessary YES as last line in
the output. Your program won't print this YES only
if before the EOF there's no EOL.
If the input file ends with the sequence EOL EOF
then you print this additional YES.
Try with 7 input numbers for example and you will see
that your program prints 8 answers.
If you don't see this effect on your machine then
I guess it is due to some portability issues
with the method cin.get() which you're using.
By portabily issues I mean it probably behaves differently
on different platforms ( could be OS dependent ?! , compiler
dependent ?! , stuff like that ).
On my machine I see an additional unnecessary YES, as I said.
I used the Borland C++ Builder 6 to compile your program
on a machine with the Windows 2000 OS.
Maybe you should try to just use Stadard C I/O functions.
For this problem using scanf will be enough and
will work fine. You just have to slightly modify the way you
handle the input.
Your algorithm is OK but your program always prints
and additional unnecessary YES as last line in
the output. Your program won't print this YES only
if before the EOF there's no EOL.
If the input file ends with the sequence EOL EOF
then you print this additional YES.
Try with 7 input numbers for example and you will see
that your program prints 8 answers.
If you don't see this effect on your machine then
I guess it is due to some portability issues
with the method cin.get() which you're using.
By portabily issues I mean it probably behaves differently
on different platforms ( could be OS dependent ?! , compiler
dependent ?! , stuff like that ).
On my machine I see an additional unnecessary YES, as I said.
I used the Borland C++ Builder 6 to compile your program
on a machine with the Windows 2000 OS.
Maybe you should try to just use Stadard C I/O functions.
For this problem using scanf will be enough and
will work fine. You just have to slightly modify the way you
handle the input.