j**7 发帖数: 143 | 1 http://www.yodlecareers.com/puzzles/triangle.html
我的答案不对 (665321)。
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("triangle.txt");
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
int value=Integer.parseInt(in.readLine().trim());
int index=0;
while ((line = in.readLine()) != null) {
String [] temp=line.split("[ ]");
int a=Integer.parseInt(temp[index]);
int b=Integer.parseInt(temp[index+1]);
if(b>a)
{
index=index+1;
value+=b;
}
else
{
value+=a;
}
}
System.out.println(value);//665321
in.close();
}catch(IOException e )
{
}
} |
A*****i 发帖数: 3587 | 2 别想了,前年我就做对了,依然没拿到面试
除非第二个杂技团的游戏也解出来
这个题典型的DP |
j**7 发帖数: 143 | 3
第一题怎么做?
【在 A*****i 的大作中提到】 : 别想了,前年我就做对了,依然没拿到面试 : 除非第二个杂技团的游戏也解出来 : 这个题典型的DP
|
j**7 发帖数: 143 | |
p*****2 发帖数: 21240 | |
B********t 发帖数: 147 | 6 是732506吗
));
【在 j**7 的大作中提到】 : http://www.yodlecareers.com/puzzles/triangle.html : 我的答案不对 (665321)。 : public static void main(String[] args) { : // TODO Auto-generated method stub : : File file = new File("triangle.txt"); : try : { : BufferedReader in = new BufferedReader(new FileReader(file)); : String line;
|
d*******3 发帖数: 58 | 7
我试了下,是732506,这题不就是leetcode triangle那题么
【在 B********t 的大作中提到】 : 是732506吗 : : ));
|
j**7 发帖数: 143 | 8 结果:732506
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("triangle.txt");
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
List list=new ArrayList();
while ((line = in.readLine()) != null) {
String [] temp=line.split("[ ]");
int [] a=new int [temp.length];
for(int i=0;i
{
a[i]=Integer.parseInt(temp[i]);
}
list.add(a);
}
for(int i=list.size()-2;i>=0;i--)
{
int [] current=list.get(i);
int [] prev=list.get(i+1);
for(int j=0;j
{
if(prev[j]>prev[j+1])
{
current[j]+=prev[j];
}
else
{
current[j]+=prev[j+1];
}
}
}
System.out.println(list.get(0)[0]);
in.close();
}catch(IOException e )
{
}
} |
e***s 发帖数: 799 | |
h********0 发帖数: 74 | 10 not find out the second with google, would you help
【在 A*****i 的大作中提到】 : 别想了,前年我就做对了,依然没拿到面试 : 除非第二个杂技团的游戏也解出来 : 这个题典型的DP
|
l***i 发帖数: 1309 | 11 I did triangle 3 years ago and immediately got an email from them. Sadly
they do not hire interns ...
The answer to triangle can be found in yahoo answer. |