Page 1 of 4
10050 - Hartals
Posted: Wed Jan 08, 2003 10:02 am
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]
Posted: Fri Jan 10, 2003 3:36 pm
by Jalal
whats the things with this:
if( ((k==6 || k==7) && k<=7) || ( (k%7==6 || k%7==0) && k>7 )) {continue; }
Posted: Fri Jan 10, 2003 8:04 pm
by Astrakan
Try this input:
Output should be 2608, not 2607.
10050?What's wrong??
Posted: Thu Jan 23, 2003 8:34 pm
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++;
}
}
}
Posted: Thu Jan 23, 2003 9:42 pm
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.
Posted: Tue Feb 25, 2003 10:28 pm
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
Posted: Tue Feb 25, 2003 11:50 pm
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:
The output should be 1, not 1 1. Hope this helps.
Posted: Wed Feb 26, 2003 10:44 pm
by yahoo
thank you very much for your reply. I have corrected your suggetion. But it still gives me wrong answer.

Can anybody give me some test inputs or can say where i am wrong. Thanks in advance.
Posted: Wed Feb 26, 2003 11:57 pm
by Astrakan
Try this input data (first line is T):
Output should be 0 (why?).
Hope this helps.
Posted: Thu Feb 27, 2003 10:34 pm
by anupam
i also tried without the while loop before, but is there any tricky case/ critical case,that i think, remains?
--anupam

Posted: Fri Feb 28, 2003 12:08 am
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:
You should probably test with larger values for P too, not just 1.
Posted: Fri Feb 28, 2003 11:07 pm
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.
10050 - What is the problem?
Posted: Tue May 06, 2003 3:51 pm
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
i think this is your mistake
Posted: Wed May 19, 2004 6:57 pm
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]
Help, what's wrong with my code???
Posted: Thu May 20, 2004 10:23 am
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]