Page 3 of 4

Posted: Sun Sep 23, 2007 3:12 pm
by Arashk_kh68
May somebody help me plz?!
I think I am encountering some serious problems here, I have coded the solution in about 5 minutes! But Im getting crazy with this judge, Cant get AC although I have tried all testcases provided here, U can check this code yourself and see what I am saying, whats wrong with my code?!

Code: Select all

// Hartals.cpp : Defines the entry point for the console application.
// UVA 10050

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int cases;
	cin >> cases; // number of cases
	
	int offs = 0; // number of working days lost
	int nDays; // total number if simultion days
	int parties; // number of parties
	
	bool* days; // array used for days counted

	for (int i = 0; i < cases; i++) {
		cin >> nDays;
		days = new bool[nDays + 1]; // + 1 to pass off by one 
		cin >> parties;

		for (int j = 0; j < parties; j++) {
			int hParam; // hartal parameter
			cin >> hParam;

			for (int k = 1; k <= nDays; k++) {
				if (days[k] && k % hParam == 0 && k % 7 != 0 && k % 7 != 6) { // checks : 1- day is counted before 2- day must be a hartal 3- day is saturday 4- day is sunday
					offs++; 
					days[k] = false; // flags the day as counted
				}
			}
		}
		delete days;
		cout << offs;
		if (i != cases - 1)
			cout << endl; // used to skip last newline
		offs = 0;
	}

	return 0;
}

Thanks in advance.

Posted: Sun Sep 23, 2007 4:54 pm
by Ion2Atom
I completed this problem not too long ago myself (I had a stupid typo), but I did it on PC. I'm still pretty new at this but if I had to guess.....

1. "days = new bool[nDays + 1];"
Is this statement automatically initialized? I am not very familiar with this style... I use vectors. :D

2. "if (days[k] && k % hParam == 0 && k % 7 != 0 && k % 7 != 6)"
Why do you do it this way? Although there is nothing wrong with this as far as I can see, you can do it much simpler by doing:

for (int k = 1; k <= nDays; k+=hParam) {
if (k % 7 != 0 && k % 7 != 6) { //not Fri. or Sat.

3. You might want to try going back to zero based for your bool array? Maybe it was just my code, but I got some bad output when I was one based. When I moved over to zero based it worked perfectly (Other than the typo above)

hartals wa

Posted: Fri Dec 14, 2007 2:36 pm
by balkrishna
accepted

Posted: Thu Mar 20, 2008 12:41 am
by lucaskt
Ok, I'm officially out of ideas. I haven't seen the program fail yet (doing tests by hand, plus getting I/O from you guys),,, what the hell's wrong with it? :P

Code: Select all

#include <iostream>
using namespace std;

int week[3650];
int hartals[101];

int main() {
	int T, P, N, h, l, d, c, x;
	cin >> T;
	for (int t = 0; t < T; t++) {
		for (int i = 0; i < 3650; i++) {
			week[i] = 0;
		}
		for (int i = 0; i <= 100; i++) {
			hartals[i] = 0;
		}

		cin >> N;
		cin >> P;
		for (int p = 0; p < P; p++) {
			cin >> h;
			if (hartals[h]) continue;
			hartals[h] = 1;

			l = 5;
			d = -1;
			while (d < N) {
				d += h;
				x = d % 7;
				if ((x != 5) && (x != 6)) {
					week[d] = 1;
				}
			}
		}

		c = 0;
		for (d = 0; d < N; d++) {
			if (week[d]) {
			//	cout << d << " ";
				c++;
			}
		}

		cout << c << endl;
	}
}
Here's the I/O I've been doing:
Input:

Code: Select all

10
14
3
3
4
8
100
4
12
15
25
40
21
3
21
6
5
10
1
1
100
1
30
3650
1
1
1
1
1
20
1
20
21
1
21
21
1
22
Output:

Code: Select all

5
15
5
8
2
2608
1
0
0
0
Any help would be appreciated.

lucaskt

Posted: Thu Mar 20, 2008 7:51 pm
by Jan
Check the case..

Input:

Code: Select all

1
2672
2
795
1945
Output:

Code: Select all

3
Hope it helps.

Re: 10050 - Hartals, WA ??

Posted: Mon Sep 03, 2012 6:44 pm
by goldenbird299
hi all
i got WA for this problem
here's my code:

Code: Select all

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <limits.h>
using namespace std;

int main()
{
	int t, n, p, h[130], cnt;
	bool b[3660];
	cin >> t;
	for(int z = 0; z < t; z++)
	{
		memset(b, 0, sizeof(b));
		cnt = 0;
		cin >> n >> p;
		for(int i = 0; i < p; i++)
			cin >> h[i];
		for(int i = 0; i < p; i++)
		{
			for(int k = h[i]-1; k < n; k+=h[i])
			{
				if(k%5 != 0 && k%6 != 0 && !b[k])//if it's not Friday nor Saturday and it's not been marked before(it's all zero-based)
				{
					b[k] = 1;
					cnt++;
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}
can anybody tell me where i'm wrong?
Thanks in advance

Re: 10050 - Hartals

Posted: Wed Sep 05, 2012 12:03 am
by brianfry713
Input:

Code: Select all

1
14
1
14
Output should be 0.

Re: 10050 - Hartals

Posted: Tue Oct 09, 2012 6:55 pm
by shuvrothpol1
why wa?
i check the given input & output and it's ok..but getting wa..
#include <stdio.h>

int main ()

{
int i,j,n,N,P,d,t,k,count;

scanf ("%d",&t);
for (j=0;j<t;j++)
{
scanf ("%d",&N);
scanf ("%d",&P);
count=0;
int a[3651]={0};
for (i=0;i<P;i++)
{
scanf ("%d",&d);
n=d;
k=2;
while (d<=N)
{
if (d%7!=6&&d%7!=0)
{
if (a[d]!=1)
{
a[d]=1;
count++;
}
}
d=n*k++;
}
}
printf ("\n%d\n",count);
}
return 0;
}

Re: 10050 - Hartals

Posted: Tue Oct 09, 2012 7:58 pm
by brianfry713
Change:
printf ("\n%d\n",count);
to:
printf ("%d\n",count);

Re: 10050 - Hartals

Posted: Tue Oct 09, 2012 9:13 pm
by shuvrothpol1
tnx, that is really silly mistake always done by me>>> :(
anyway, how can i delete my previous post??

Re: 10050 - Hartals

Posted: Wed Oct 10, 2012 6:43 pm
by brianfry713
It is probably too late to delete your post after I responded to it. You could edit it out by logging in and then clicking edit next to the post.

Re: 10050 - Hartals

Posted: Fri May 17, 2013 2:14 pm
by mobarak.islam
@brianfry713 : Here I'm getting wrong answer . I checked all the input output sample regarding this problem and got the appropriate answer.But its getting WA :(
BTW Thank you for your help in my previous problem.

Code is deleted after getting AC .

Re: 10050 - Hartals

Posted: Fri May 17, 2013 11:44 pm
by brianfry713
Input:

Code: Select all

10
1685
3
1473
975
726
2614
7
1371
2162
2487
906
2179
1858
16
3585
2
908
1112
882
9
29
640
493
431
577
653
523
243
4
1379
12
32
956
1198
451
89
562
837
143
719
34
951
365
2620
10
2
2530
461
1658
297
1929
1923
152
463
2202
2690
6
2545
2348
1959
209
577
967
2130
12
888
877
813
2049
954
310
1765
1920
1951
1294
1033
1032
814
1
794
370
4
120
121
87
226
AC output:

Code: Select all

4
121
5
183
86
946
16
19
1
9

Re: 10050 - Hartals

Posted: Sat May 18, 2013 1:16 am
by mobarak.islam
@ brianfry713: I checked all the sample input -output given by you and i got AC. But I'm still getting WA while submitting :(

Re: 10050 - Hartals

Posted: Tue May 21, 2013 2:47 am
by brianfry713
The code you posted does not match the I/O I posted. See: https://ideone.com/y3bpwf