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

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 10050 - Hartals

Post by mobarak.islam »

@ brianfry713:Thanks for your reply . but I checked your link with I/O. There is a problem in your output .
When input is :
3585
2
908
1112

Correct Ans would be 5 ( http://uvatoolkit.com/problemssolve.php ). My code also generate this answer.
but in your link ,it is 66
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10050 - Hartals

Post by brianfry713 »

Yes for input:

Code: Select all

1
3585
2
908
1112
AC output is 5. This link https://ideone.com/D1195a is YOUR code, not mine, it's what you posted in this thread. It does not produce the correct answer.
Check input and AC output for thousands of problems on uDebug!
mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 10050 - Hartals

Post by mobarak.islam »

@ brianfry713: I'm confused here :S
I checked my code by Microsoft Visual Studio 2005 and it gives following input -output

Input:
1
3585
2
908
1112

Output:
5


but here (https://ideone.com/D1195a )
sometimes it gives 66 and sometimes 57
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10050 - Hartals

Post by brianfry713 »

You need to initialize the D array before you use it.
Check input and AC output for thousands of problems on uDebug!
mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 10050 - Hartals

Post by mobarak.islam »

brianfry713: Finally I got AC :) Thank You very much .
me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

10050 - Hartals Why WA?????

Post by me33 »

Please Help..
getting continuously WA..

here is my code...

Code: Select all

#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,p,hartal;
        scanf("%d %d",&n,&p);
        int res[n];
        for(int i=0;i<n;i++)res[i]=0;
        for(int i=0;i<p;i++){
            scanf("%d",&hartal);
            for(int j=hartal;j<n;j+=hartal){
                res[j]=1;
            }
        }
        p=0;
        for(int i=0;i<n;i++){
            if((i+1)%7!=0&&i%7!=0&&res[i]==1)p++;
        }
        printf("%d\n",p);
    }
    return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10050 - Hartals Why WA?????

Post by brianfry713 »

Post in the appropriate forum, volume C instead of General.
Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

Re: 10050 - Hartals Why WA?????

Post by me33 »

brianfry713 wrote:Post in the appropriate forum, volume C instead of General.
Try running your code on the sample input.
My code runs well for all sample input...
Plz check and help. :(
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10050 - Hartals Why WA?????

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
maddi
New poster
Posts: 6
Joined: Sat Jun 07, 2014 12:07 am

uva 10050 -hartals Why i am getting RE in this code?

Post by maddi »

i have tested with the sample inputs and it works fine.But uva is giving RE :(..please someone help me out.

Code: Select all

package pkg10050.hartals;

import java.util.Arrays;
import java.util.Scanner;

class Hartals {

    public static void main(String[] args) {
        new Hartals().run();
    }

    void run() {
        Scanner in = new Scanner(System.in);
        int days[];
        int Total_case, No_of_days, Total_Parties, p;
        
        Total_case = in.nextInt();
        
        for (int j = 1; j <= Total_case; j++) {
        
            No_of_days = in.nextInt();
        
            days = new int[No_of_days+1];
            Arrays.fill(days, -1);
            
            for (int k = 6; k <= No_of_days; k += 7) {
                days[k] = 0;
            }
            
            Total_Parties = in.nextInt();
            int total_hartals = 0;
            
            for (int i = 1; i <= Total_Parties; i++) {
                
                p = in.nextInt();
                int hartal_days = p;
                
                while (hartal_days <= No_of_days) {
                
                    if (hartal_days % 7 != 0 && days[hartal_days] == -1) {
                        total_hartals++;
                        days[hartal_days] = 1;
                    }
                    hartal_days += p;
                }
            }
            System.out.println(total_hartals);
        }
    }
}
maddi
New poster
Posts: 6
Joined: Sat Jun 07, 2014 12:07 am

uva 10050 -hartals Why i am getting RE in this code?

Post by maddi »

i got AC using same logic in C++.But using java i am getting RE.Please help me out :(

Code: Select all

//package pkg10050.hartals;

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

class Hartals {

    public static void main(String[] args) throws FileNotFoundException {
        
        new Hartals().run();
    }

    void run() throws FileNotFoundException {
 //       System.setOut(new PrintStream(new FileOutputStream("o.txt")));
 //       System.setIn(new FileInputStream(new File("i.txt")));
        
        Scanner in = new Scanner(System.in);
        int days[];
        int Total_case, No_of_days, Total_Parties, p;
        
        Total_case = in.nextInt();
        
        for (int j = 1; j <= Total_case; j++) {
        
            No_of_days = in.nextInt();
            days = new int[No_of_days+1];
            Arrays.fill(days, -1);
                      
            Total_Parties = in.nextInt();
            int total_hartals = 0;
            
            for (int i = 1; i <= Total_Parties; i++) {
                
                p = in.nextInt();
                int hartal_days = p;
                
                while (hartal_days <= No_of_days) {
                
                    if (hartal_days%7!=6 && hartal_days % 7 != 0 && days[hartal_days] == -1) {
                        total_hartals++;
                        days[hartal_days] = 1;
                    }
                    hartal_days += p;
                }
            }
            System.out.println(total_hartals);
        }
    }
}
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: uva 10050 -hartals Why i am getting RE in this code?

Post by uDebug »

maddi wrote:i got AC using same logic in C++.But using java i am getting RE.Please help me out :(
See the submission specs for Java

https://uva.onlinejudge.org/index.php?o ... &Itemid=30

Your class needs to changed from "Hartals" to "Main".
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
maddi
New poster
Posts: 6
Joined: Sat Jun 07, 2014 12:07 am

Re: uva 10050 -hartals Why i am getting RE in this code?

Post by maddi »

memberlist.php?mode=viewprofile&u=99347 thanks a lot man.I have been eagerly waiting for any kind help regarding this.
Finally,got AC.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: uva 10050 -hartals Why i am getting RE in this code?

Post by uDebug »

maddi wrote:thanks a lot man.I have been eagerly waiting for any kind help regarding this.
Finally,got AC.
Glad you figured it out.

Next time please post in the existing thread for the problem

viewtopic.php?f=9&t=2058&hilit=10050

And do not create a new one.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
yukiyoru98
New poster
Posts: 1
Joined: Sat Sep 19, 2015 8:35 am

Re: 10050 - Hartals

Post by yukiyoru98 »

Plz help...What's wrong with this code??

Code: Select all


#include <stdio.h>

int main()
{
    int T=0;
    scanf("%d", &T);
    for(int cnt=0; cnt<T; cnt++)
    {
        int n=0, p=0, k=0;
        int arr[3650]={0};
        scanf("%d", &n);
        scanf("%d", &p);
        for(int i=0; i<p; i++)
        {
            int h=0;
            scanf("%d", &h);
            for(int j=1; j<=n/h; j++)
            {
                if((h*j+1)%7==0)    continue;
                arr[h*j]=1;
            }
        }
        for(int l=1; l<=n; l++)
        {
            if(arr[l]==1)   k++;
            else continue;
        }
        printf("%d\n", k);
    }
    return 0;

}
Post Reply

Return to “Volume 100 (10000-10099)”