10050 - Hartals

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

fzrone
New poster
Posts: 4
Joined: Mon Jan 06, 2003 2:26 pm
Location: Indonesia, Jakarta

10050 - Hartals

Post by fzrone »

plese help me
this should be easy
[c]

#include<stdio.h>

int main() {
int i,j,k,h,y,p,hr[3650],ans,n,c;


while(scanf("%d" ,&c)==1) {
n=0;

do{
ans=0;
if(n>=c) break;
for(i=0;i<3650;i++) hr=0;

scanf("%d", &h);
if(h<7||h>3650)break;

scanf("%d", &p);
if(p<1||p>100)break;

for(j=0;j<p;j++) {
k=y=0;
scanf("%d", &y);
if(y%7==0&&y>7) break;
while(1) {
k+=y;
if(k>h) break;
if( ((k==6 || k==7) && k<=7) || ( (k%7==6 || k%7==0) && k>7 )) {continue; }
else hr[k]=1;
}
}
if(y%7==0&&y>7) break;

for(i=0;i<3650;i++) if(hr==1 ) ans++;
printf("%d\n",ans);
n++;

}while(1);
}


return 1;
}


:( [/c]
Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

whats the things with this:
if( ((k==6 || k==7) && k<=7) || ( (k%7==6 || k%7==0) && k>7 )) {continue; }
Last edited by Jalal on Wed Feb 26, 2003 6:20 am, edited 1 time in total.
Astrakan
New poster
Posts: 24
Joined: Sun Nov 03, 2002 12:18 pm
Location: Sweden

Post by Astrakan »

Try this input:

Code: Select all

1
3650
1
1
Output should be 2608, not 2607.
razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Location: SUST,BANGLADESH
Contact:

10050?What's wrong??

Post by razibcse »

can anyone help me with this WA...
i thot it would b easy

Code: Select all

#include <stdio.h>

#define MAX 3700

void crossout(long par);
long n,hartal[MAX],hp[MAX],count;
void main()
{

long p,a,b,t,cut;
scanf("%ld",&t);
for(a=0;a<t;a++)
 {
 count=0;
 scanf("%ld",&n);
 scanf("%ld",&p);
 for(b=1;b<=p;b++)
  scanf("%ld",&hp[b]); 

 for(b=1;b<=n;b++)
   hartal[b]=b;

 for(b=1;b<=n;b++)
    {
    if((b%7)==0)
      {
      hartal[b-1]=-1;
      hartal[b]=-1;
      }
    else
      hartal[b]=1;
    }


 for(b=1;b<=p;b++)
  {
  cut=hp[b];
  crossout(cut);
  }
  printf("%ld\n",count);
 }

}

void crossout(long par)
{
long x;
for(x=par;x<=n;x+=par)
  {
  if(hartal[x]!=0 && hartal[x]!=-1)
    {
    hartal[x]=0;
    count++;
    }
  }
}
Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

I didnt take a good look on ur code.
but u may cheak the following thing:
void crossout(long par)
{
long x;
for(x=par;x<=n;x+=par)
{
if(hartal[x]!=0 && hartal[x]!=-1)
{
hartal[x]=0;
count++;
}
}
}

in the first loop better to count in x++ inplace of x+=par.
User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

This problem seems to be easy to me but i always got wrong answer. Can anybody give me some test cases. I think some thing may be typical which i am missing. Thanks in advance. Here is my code:

Code: Select all

the code is cut off because after some modification is
Last edited by yahoo on Fri Feb 28, 2003 11:16 pm, edited 1 time in total.
Astrakan
New poster
Posts: 24
Joined: Sun Nov 03, 2002 12:18 pm
Location: Sweden

Post by Astrakan »

Yahoo, this part is dubious:
[c]while(1)
{
r=scanf("%d" ,&n);
if(r==EOF) break; [/c]
You should not try to read until EOF. According to the specification, "The first line of the input consists of a single integer T giving the number of test cases to follow. " Read the number of cases once, read and process those cases, and terminate.

Consider this input data:

Code: Select all

1
1
1
1

1
The output should be 1, not 1 1. Hope this helps.
User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

thank you very much for your reply. I have corrected your suggetion. But it still gives me wrong answer. :oops: :oops: :oops: Can anybody give me some test inputs or can say where i am wrong. Thanks in advance.
Astrakan
New poster
Posts: 24
Joined: Sun Nov 03, 2002 12:18 pm
Location: Sweden

Post by Astrakan »

Try this input data (first line is T):

Code: Select all

1
20
1
20
Output should be 0 (why?).

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

Post by anupam »

i also tried without the while loop before, but is there any tricky case/ critical case,that i think, remains?
--anupam :oops: :oops: :oops:
"Everything should be made simple, but not always simpler"
Astrakan
New poster
Posts: 24
Joined: Sun Nov 03, 2002 12:18 pm
Location: Sweden

Post by Astrakan »

This problem is quite easy. The cases you might want to check are boundary cases, like N=3650, P=1, P=100 etc., and those when a hartal occurs on the last day of the simulation or the day after the last.

This input

Code: Select all

6
1
1
1
3650
1
1
20
1
20
21
1
21
21
1
22
22
1
22
should give this output:

Code: Select all

1
2608
0
0
0
1
You should probably test with larger values for P too, not just 1.
User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

Post by yahoo »

Thank you very very much astrakan for your help. I had done a silly miktake. I have corrected it and got accepted. Thanks again.
Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Location: St. Johns, Canada
Contact:

10050 - What is the problem?

Post by Master »


Can anyone tell what is the problem with the following two codes? The first one I made and submit a few times and got the WA. Once a day my friend (ZP) came and tells me that he got AC on this problem. So I take his code to find out what is my fault. But I can
Alec
New poster
Posts: 8
Joined: Sun Mar 28, 2004 9:00 pm

i think this is your mistake

Post by Alec »

[cpp]
#include<iostream.h>

#define MAX 3655

void sim(int day)
{
int a[MAX*2]={0};
register int i,j;
unsigned long long h;
cin >> i;
for(;i>0;i--)
{
cin >> h;
for(j=1;(j*h) <= day ;j++)
a[j*h]=1;
}

for(i=7;(i-1)<=day;i+=7)//i fixed this line,see?
a=a[i-1]=0;

j=0;
for(i=1;i<=day;i++)
j += a;
cout << j << endl;
}

main(void)
{
int t,day;
cin >> t;
for(;t>0;t--)
{
cin >> day;
sim(day);
}
return 0;
}
[/cpp][/cpp]
r_nest23
New poster
Posts: 1
Joined: Thu May 20, 2004 10:17 am

Help, what's wrong with my code???

Post by r_nest23 »

What's wrong with this code? I've submitted for few times and the result is WA. Please help.....

[cpp]#include<iostream.h>

main(void)
{
int except,x,i,j,k;
int day,noparty,freq,tmp;
int *daystat;
int *result;

cin >> x;
if (x>0) {
result = new int[x];

for(i=0; i<x; i++) {
cin >> day;
cin >> noparty;

daystat = new int[day];

for(j=0; j<noparty; j++) {
tmp=-1;
cin >> freq;
while(tmp<=day-1) {
tmp+=freq;
if (tmp<=day-1) daystat[tmp]=1;
}
}

except=-2;

while(except<=day-1) {
except+=7;
if(except<=day-1) daystat[except]=0;
}

except=-1;

while(except<=day-1) {
except+=7;
if(except<=day-1) daystat[except]=0;
}

result=0;
for(k=0; k<day; k++) {
if(daystat[k]==1) result++;
}

delete [] daystat;
}

for(i=0; i<x; i++) cout << result << endl;

delete [] result;
} else cout << 0 << endl;
return 0;
}[/cpp]
Post Reply

Return to “Volume 100 (10000-10099)”