Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all 39796 articles
Browse latest View live

collection.shuffle does not work in java netbeans 8.2

$
0
0

I am trying to shuffle JButton using collections.shuffle(),but it does not work when I run the program...

this is my code :

 /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package projetu;

    import java.awt.*;
    import java.util.*;

    /**
     *
     * @author USER
     */
    public class NewMain extends JFrame{

        /**
         * @param args the command line arguments
         */

           final int row =3;
           final int col =3;
           javax.swing.JPanel panel;
           javax.swing.JButton button[];
           List<javax.swing.JButton> arrlist = new ArrayList();

        public NewMain (){
            panel = new javax.swing.JPanel();
            panel.setLayout(new GridLayout(row,col));

        button = new javax.swing.JButton[9];
        for (int i=0; i<9; i++){

            button[i] = new javax.swing.JButton(String.valueOf(i));
            panel.add(button[i]);

        arrlist.add(button[i]);

        Collections.shuffle(arrlist);

        }


        add(panel);
        setSize(300,300);
        setVisible(true);
        } //end of script 0001

             public static void main(String[] args) {
            // TODO code application logic here

            NewMain n=new NewMain();


    }


    }

Express a number as sum of consecutive numbers

$
0
0

In how many ways can a number be expressed as a sum of consecutive numbers?

INPUT

15

OUTPUT

3

INPUT

10

OUTPUT

1

is there any simple logic for this question :).

please upvote me i was unable to ask question because i have only 1 karma point.

Please help me in SUMQ

$
0
0

Request help for Triplets(SUMQ) from June 2017 long challenge. I arrived at the following optimization (http://ideone.com/nSLdfk) however I got a WA for all my test cases. I would be thankful if anyone could take a look. Regards.

Help me in Knight's tour problem

$
0
0

Please help me with this code. I don't know why is it not printing the output. The code is based on Warnsdorff’s algorithm for Knight’s tour problem.

https://ideone.com/XMWuV3

What does the execution time displayed for my submission mean?

$
0
0

I just submitted a solution for one of the problems on CodeChef. There is something called as execution time displayed after I got a corrected answer. What does it mean?

PLZLYKME - Editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Kaushik Iska
Tester:Mahbub
Editorialist:Jingbo Shang

DIFFICULTY:

Simple

PREREQUISITES:

Programming Language

PROBLEM:

Define F[1] = S, F[i > 0] = F[i - 1] * (C + 1). Determine whether F[D] >= L.

EXPLANATION:

First of all ,we need to observe that F[] is monotone increasing, because of (C + 1) > 1.

Second, F[] is increasing exponentially, while L is smaller than 10^9. That means, only O(log L) days are needed for F[D] to exceed L.

Third, when F[] exceed L, it is possible about 10^18 (exceeding int in C++ and Java). So please choose the appropriate type to store.

In summary, what we need to do is calculate F[0..D] one by one, until all D + 1 ones are got or some one is greater than L. The time complexity is in O(min{D, log L}).

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

Require a list of tutorials posted on codechef

$
0
0

I have seen a lot of good tutorials on codechef but I am unable to find them properly as with time, new questions overcrowd the forum (discuss.codechef). I have seen a couple of discussions on required algorithms and data structure for competitive coding. Has there been any discussion where links to all the tutorials (on codechef only) is posted? If so, kindly provide the link.

Here are a few (recent articles) I found. I am sure there are much more available.

extended euclid algorithm

persistent segment tree

merge sort tree

Intro to graph

suffix array

debugging NZEC

bit masking

array

stack

Want official Editorials for June long'17.

$
0
0

When will be the official editorials available for june long challenge'17?


Chef and feast june 17 challenge

Chef and feast june 17 challenge

modulus operator

$
0
0

can somebody explain me that how modulus operator works and if i have two integer of value equal to 10^100 each then how i find the product with the help of inverse modulo?

NEO01 - EDITORIAL (Unofficial)

$
0
0

PROBLEM LINK

Practice
Contest

CONTEST PANEL

Author:neo1tech9_7

PREREQUISITES

Basic Math

DIFFICULTY

EASY

PROBLEM

An array with N elements (both positive and negative) is given, a term happiness is defined as the sum of all elements of a selected subset from given array multiplied by the number of elements in it. A element from the array can be taken in a subset only once and all elements must appear in some subset, find the maximum value of happiness possible.

EXPLANATION

Complexity:O(nlogn)

Subtask 1:

This subtask consists of all negative array elements, so to maximise the happiness we select a subset of 1 element for all array elements i.e simply the summation of all array elements.

Subtask 2:

As anyone would guess, to maximise happiness we need to select a subset whose sum*(number of terms) is the greatest.

To start off with my solution what I do is pre-calculate the sum of subset of all positive numbers and subset of all negative numbers and take note of count of positive numbers and zeroes and store absolute values of negative numbers in an array or vector and sort it in ascending fashion.

So for our initially selected subset (set of all non-negative values) we are at happiness=(positive sum)*(count of positive numbers and zeroes).

for example:
A = {10,5,-1,-2,-3}
starting subset = {10,5}
starting happiness = (10+5)*(2) = 30
negative vector = {1,2,3} (Recall that we took absolute values)

Note: We are adding absolute values of all negative numbers and will be testing whether the number will be appearing in the subset from smallest absolute value to greatest.

Find the proof for this greedy algorithm in the answer by @hikarico.

Note that this selected initial subset is dynamic and we will check whether the addition of negative numbers (from smallest absolute value to the greatest) will result in happiness greater than what we have at present and if addition of negative numbers in the selected subset results in a greater happiness we insert that negative value in the subset, refer the pseudocode below for clarification.
accumulator = subset length sum = subset sum ans = accumulator*sum for(i from 0 to length of negative array){ if((sum-negative[i])*(accumulator) greater than ans){ ans = (sum-negative[i])*(accumulator+1); sum-=negative[i]; accumulator++; } }
After you've done this you are at a situation where no addition of negative numbers in the subset will result in greater happiness so what we do is make subsets of one element for all the remaining negative elements not in any subset and thus subtract all the remaining negative numbers from happiness.

Thus this is how we arrive at max happiness possible.

Do feel free to share your approach and feel free to comment if you have any doubt :D

SOLUTION

My AC
Execution Time: 0.1 s
Memory: 3.3M

depressed from myself because i wasted my 4 semesters? depressed! dont know what to do now?

$
0
0

now i m in 5th semester, i started programing 5 months earlier (in my 4th semester).. Now i am able to solve overall 4 question on long challenge... i have wasted my 2 years of college life.. its not like that i havn't studied but my direction of studies was not in right direction. i am from very small private college where no senior is available for guidence (like what is good or not), after failing in jee advanced, i decided to work hard in college but now it seems like i wasted my very important 2 years of life.. i heard about compitive programing, codechef, geeksforgeeks words in my second year... i like compitive programing but i wasted my 2 years, this thing is distrubing me mentally . i thinks daily to work hard and code regularly but not able to execute what i plan but after looking at guys like @vijju123j and many more, who started compitive programing from their first year of college even he is studying in bits college where no issue for placement for good students, he is working so hard other hand me, studying in very small private college and i wasted my 2 years...
Now this things distrubs me mentally that , i am minimun 1 year behind from the other college student.. how can i fill that 1 year gap i asked this here because i need some motivation that even now i can achive good in life..

buffered vs normal i/o

$
0
0

i see many solutions in codechef in c c++ using buffered i/o and other complex i/o methods. a simple 5 line code becomes a complex looking code of 2 page using buffers etc. but the running time is considerably affected. my simple code in which i use scanf printf cin cout takes 2-5 seconds for running while these buffered i/o solutions run in about 0.13 seconds. how is that ???? please post a tutorial so that we can read it and understand it and may be use it in future ....

i have referred to c and c++ .......... plz answer

1974 ACM-ICPC World Finals Problem

$
0
0

Given an array of String containing the dimensions to create a figure, we have to calculate the area of the figure created from the string array.

Example : If the string array contains {"N2" , "E2" , "S2" , "W2"} N -> North E->East and so on. The above array represents a square with side 2.

Similarly any figure can be created with at most 12 corners and assume that we always end on the corner on which we started. I used 2-D matrix to first create the figure using 1s and 0s and then calculated the area.

Is there any better approach to solving this problem as my program gives wrong answer for one case? The exact question can be found here :http://icpc.baylor.edu/ICPCWiki/attach/Problem%20Resources/1974-Texas.pdf


More information on wrong results

$
0
0

Why is there so little information when the uploaded solutions end up wrong? Shouldn't we be able to get a bit of input on what went wrong by, for example, receiving the test-case in which it failed?

Otherwise, we end up blindly trying to fix a problem that we have no idea what it is.

This would make sense if we had a system that rewarded users for having a near-correct solution. An example of this is an exam in some class. The student doesn't know the solution when he is doing the exam, but he's score is given based on how good is solution was, even if it ended up not being completely correct.

This scoring system, however, does not provide any input on what you did wrong and does not provide any score unless you successively completed the problem.

calculation of time during different Server load

$
0
0

I want to calculate execution time of a program (in C) as a part of my academic project.Could you please tell me how you are calculating time(execution time) for a program accurately during different server load periods?

Learnig Java

$
0
0

I m doing my b.tech(2nd Year) from Galgotias college . I started learning java from a book by e balagurusamy Programming with Java. But im facing some prblms understanding the concept of class, method and object . Please tell me only basic information about these topics, i don't have any problem in programming but with meanings and concept of these new things. I know C language only.

Codechef Rating Predictor

$
0
0

Hello everyone!

alt text

Codechef Rating Predictor

The delay in previous month rating changes + inspiration from CF Predictor and for the practice of a web-application, i tried to write a script that can predict rating changes from ongoing live contests @ Codechef.

While the actual delays in rating changes s/would be fixed, this script can help in predicting rating changes as new submissions are made, so hopefully it can be useful for Long contests :).

The script is written in nodejs and is based on open rating formulas available at this link. The code for the project can be accessed here

Website is currently hosted on Openshift free servers and has few restrictions on use. Therefore the server might be slow or not responding during the period rating changes are calculated. Currently, ratings are expected to be updated every 15 minutes

I also tested rating changes on few past contests and the predictions were accurate within an error of 2 for almost everyone except the first rank (I have no idea why first rank predictions are wrong in some contests using current formulas)

Please note that project is still in beta stage and also actual changes might differ more due to changes in ranklist after plagiarism detection

Your feedback/suggestions would be appreciated

JUNE17 Links:

All: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JUNE17/all/

Long: http://codechef-rating-predictor.7e14.starter-us-west-2.openshiftapps.com/contest/JUNE17/long/

Few stats on JUNE17 Predictions. I matched ratings (All) of first 6391 users and the results were as follows:

Difference - No of users

  • 0 - 5868
  • 1 - 275
  • 2 - 125
  • 3 - 68
  • >= 4 - 55

There were around 40 users having difference > 50. Turns out some usernames appears to be missing in the ranklist when sorted by rank and hence they were showing as last in the prediction list.

I ran the code again after fixing the above bug and results are better now (Maximum difference is 8)

  • 0 - 5900
  • 1 - 485
  • >= 2 - 6

Suggestion to add Fidget Spinner as a goody

$
0
0

I finally got some Laddus, so I headed to the Codechef store and suprisingly there are only 2 items that can be got for under 2000 Laddus (Excluding the pen that costs 1000, pretty sure no one would get it)!

As programmers, I think we tend to get fidgety while thinking for a solution to a problem. And since they are trending, it would be great to have a fidget spinner with a giant "Codechef" written on it. #ShowOff

Any Opinion on it?

Viewing all 39796 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>