夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

SRM497にあたって砕けてきた。

さっそく更新でございます。

今し方SRM497に挑戦してきました。
(リアルタイムで挑戦したのはこれが初めて。)


さて、TopCoderは250,500,1000の三つの問題があるのですが、結論を言いますと…

一問もとけませんでしたorz

やっぱ勉強おわってないのにやるのは無謀でした。
いちいちググっていって、コンパイルエラーが出まくって結局とった行動といえばエラーでるとこコメントアウト潰し

笑えませんね(^^;)


そして苦戦した問題(一番簡単な250ですw)はコチラ↓

Problem Statement
You recently got a job at a company that designs various kinds of filters, and today, you've been given your first task. A client needs a filter that accepts some objects and rejects some other objects based on their size. The requirements are described in the int sizes and the String outcome. If character i in outcome is 'A', then all objexts of size sizes[i] must be accepted, and if character i is 'R', then all objects of size sizes[i] must be rejected. If an object's size does not appear in sizes, then it doesn't matter if it is accepted or rejected.
Unfortunately, your knowledge of fileters is very limited, and you can only design filters of one specific kind called (A, B)-filters. Each filter is characterized by two integers A and B. It accepts an object if and only if its size is between A and B, inclusive. You have exellent (A, B)-filter construction skills, so you can construct any such filter where 1 <= A <= B.
If it is possible to construct an (A, B)-filter that fulfills all the requirements descibed in sizes and outcome, return a int
containing the filter's parameters, where element 0 is A and element 1 is B. If there are several appropriate filters, choose the one that minimizes B - A. If there are no suitable filters, return an empty int.
Definition
Class: Filtering
Method: designFParameters: int
, String
Returns: int
Method signature: int
designFilter(int[] sizes, String outcome)
(be sure your method is public)ilter
The problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

なんで持ってきたかって?

はい。
模範解答を教えてくださいm(_ _)m

あ、一応僕の結局コンパイルできなかった糞コードも載せますね。

import java.lang.String;

public class Filtering {
        public int[] designFilter(int[] sizes, String outcome) {
                char[] str;
                int long_str = outcome.length();
                for (int i = 0; i < long_str; i++) {
                        str[i] = outcome.substring(i, i+1);
                }
                int[] R, A;
                int r = 0;
                int a = 0;
                for (int j = 0; j < long_str; j++) {
                        if (str[j].equals("R")) { R[r] = str[j]; r++;}
                        else if (str[j].equals("A")) {A[a] = str[j]; a++;}
                }
                Allays.sort(A);
                Allays.sort(R);
                int[] ans;
                for (int n = 0; n < R.length; n++) {
                        for (int m = 0; m < A.length; m++) {
                                if (A[m] < R[n]) {
                                       if(A[m+1] < R[n]) {
                                                if (A[m+2] < R[n]) {
                                                        ans[0] = A[m];
                                                        for (int p = 0; p < A.length-(m+3); p++) {
                                                                if(A[m+2+p] > R[n]) {ans[1] = A[m+2+p]; break;}
                                                                else {continue;}
                                                        }
                                                        break;
                                                } else {
                                                        continue;
                                                }
                                        } else {
                                                continue;
                                        }
                                } else {
                                        continue;
                                }
                        }
                }
                return ans;
        }
}

はぁ〜。もっと勉強しなきゃ…

広告を非表示にする