スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

Top Coder Single Round Match 504 DIV2

Problem Statement

Comparer-inator is a very simple language that is specialized in comparisons. It takes an expression and returns the result. There are only two kinds of expressions: a variable name or a tertiary operator inspired by C syntax (which is also used in many languages like Java, C++, and C#). We are interested to use this language to process two int[]s, A and B to generate the int[] wanted as a result. We have previously found that there are four candidate programs that could be an optimal way to solve the issue we have. Each of the programs takes two arguments a and b.
"a" : This program will return the given argument a.
"b" : This program will return the given argument b.
"a"a Given int[] A, B and wanted find the shortest of the four candidate programs that, for every index i, will return wanted[i] after being provided a=A[i] and b=B[i] as arguments. Return the length of the shortest program. If no candidate program can do the required job, return -1 instead.
Definition

Class:
ComparerInator
Method:
makeProgram
Parameters:
int[], int[], int[]
Returns:
int
Method signature:
int makeProgram(int[] A, int[] B, int[] wanted)
(be sure your method is public)


Constraints
-
A will contain between 1 and 50 elements, inclusive.
-
B and wanted will each contain the same number of elements as A.
-
Each element of A, B and wanted will be between 1 and 1000, inclusive.
Examples
0)


{1}
{2}
{2}
Returns: 1
"b" and "a1)


{1,3}
{2,1}
{2,3}
Returns: 7
"a2)


{1,3,5}
{2,1,7}
{2,3,5}
Returns: -1
None of the four programs can do the job correctly.
3)


{1,3,5}
{2,1,7}
{1,3,5}
Returns: 1

4)


{1,2,3,4,5,6,7,8,9,10,11}
{5,4,7,8,3,1,1,2,3,4,6}
{1,2,3,4,3,1,1,2,3,4,6}
Returns: 7

5)


{1,5,6,7,8}
{1,5,6,7,8}
{1,5,6,7,8}
Returns: 1
"a", "b", "aThis 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.

正直、問題文の意味がわからなかった。。。
大意はこんな感じか。。
4つの代表的なプログラムのうち、配列wantedを生成する事のできる最も短いプログラム名を見つけてください。
その長さを返すようにしてください。





public class ComparerInator{

public int makeProgram(int[] A, int[] B, int[] wanted){
if(checkSimply(A, wanted))return 1;/* a */
if(checkSimply(B, wanted))return 1;/* b */
if(checkByTernaryOperator(A, B, wanted)) return 7;/* a if(checkByTernaryOperator(B, A, wanted)) return 7;/* a return -1;
}

private boolean checkSimply(int[] array, int[] wanted){
int idx;
for(idx=0;idx if(array[idx] != wanted[idx])
return false;
}
/* check complete */
return true;
}
private boolean checkByTernaryOperator(int[] array1, int[] array2, int[]wanted){
for(int idx=0;idx int candidate = array1[idx] if(candidate != wanted[idx])
return false;
}
/* check complete */
return true;
}



}
スポンサーサイト
プロフィール

tjnet777

Author:tjnet777
Solaris, VPNのサポート業務を1年

金融系SIerで業務アプリの開発、メンテを3年半

離職して大学院大学 1年生

最新記事
最新コメント
最新トラックバック
月別アーカイブ
カテゴリ
検索フォーム
RSSリンクの表示
リンク
ブロとも申請フォーム

この人とブロともになる

QRコード
QR
上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。