Sie sind auf Seite 1von 6

ACM-ICPC Indonesia National Contest 2013 - Practice Session

Problem A

The Best Team


Time Limit: 2s

ACM-ICPC 2010 (notice that this problem is taken from an old archieve) is drawing near and your university want to select three out of
N students to form the best team. The university however, has a limited budget, so they can only afford to send one team. The coach
wants his best team to be the best in term of compatibility. The compatibility of a team which member is student A, B and C is calculated
by PA,B * PA,C * PB,C, where Pi,j is the compatibility of student i and student j.
Given Pi,j for all pair of students, calculate the highest compatibility value that can be achieved by any team of three students.

Input
The first line of input contains an integer T (1 T 100) the number of cases. Each case begins with an integer N (3 N 50) the
number of students. The next N lines each contains N integers P i,j (0 Pi,j 100). The ith line and jthinteger denotes the compatibility of
student i with student j. You may assume Pi,j = Pj,i and Pi,i = 0.

Output
For each test case, output in a line the highest compatibility value that can be achieved by any team of three students.

Sample Input

Output for Sample Input

2
3
0
2
5
4
0
3
5
4

Case #1: 80
Case #2: 160

2 5
0 8
8 0
3
0
2
6

5
2
0
8

4
6
8
0

Explanation for the 1st sample input.


There are only three students so the coach has no choice but to select them.
Explanation for the 2nd sample input.
The best combination would be choosing student 1, 3 and 4.

C/C++ solution
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int T;
scanf( "%d", &T );
for ( int tc = 1; tc <= T; tc++ ) {
int N, P[55][55];
scanf( "%d", &N );
for ( int i = 0; i < N; i++ )
for ( int j = 0; j < N; j++ )
scanf( "%d", &P[i][j] );
int ans = 0;
for ( int i = 0; i < N; i++ )
for ( int j = i + 1; j < N; j++ )
for ( int k = j + 1; k < N; k++ )
ans = max(ans,P[i][j]*P[i][k]*P[j][k]);
printf( "Case #%d: %d\n", tc, ans );
}
return 0;
}

Java solution
import java.util.*;
import java.lang.Math;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for ( int tc = 1; tc <= T; tc++ ) {
int P[][] = new int[55][55];
int N = scan.nextInt();
for ( int i = 0; i < N; i++ )
for ( int j = 0; j < N; j++ )
P[i][j] = scan.nextInt();
int ans = 0;
for ( int i = 0; i < N; i++ )
for ( int j = i + 1; j < N; j++ )
for ( int k = j + 1; k < N; k++ )
ans = Math.max(ans,P[i][j]*P[i][k]*P[j][k]);
System.out.printf( "Case #%d: %d\n", tc, ans );
}
}
}

Source: ACM-ICPC Indonesia National Contest 2010

ACM-ICPC Indonesia National Contest 2013 - Practice Session

Problem C

Time Zone Conversion


Time Limit: 2s

Leslie had a hard time understanding GMT time zone conversion although many of her friends had helped her with this problem. Thus,
she often gets a wrong time when making an appointment with her friend in other time zone. Her friends are annoyed with this problem
so they decided to write a program which will help her. But programming is not their strong point, so they asked you to help them.
Given a time in GMT+A you have to convert it into GMT+B. GMT+X means the time in that area is X hours ahead of GMT+0, while
GMT-X means its time is X hours behind GMT+0. For example, 15:00 GMT+7 means 08:00 GMT+0 (same day) and 20:00 GMT-5 is
01:00 GMT+0 (one day ahead).
Note that the hour part of a time is between 0 and 23, inclusive, there's no 24. So, midnight time is 00:00 and it is the beginning of a
new day. In this problem you don't have to deal with Daylight Saving Time (DST).

Input
The first line of input contains an integer T (1 T 100) the number of cases. Each case contains three integers A (-11 A 11), B (-11
B 11) and M (0 M 23) denoting an input at time M (only the hour) in GMT+A and you're going to calculate the time in GMT+B.

Output
For each case, output in a line "Case #X: Y Z" where X is the case number, starting from 1, Y is the time in GMT+B (output only the
hour) and Z is either -1, 0, 1 representing that the time is one day behind, in the same day, or one day ahead respectively.

Sample Input

Output for Sample Input

5
7 8 15
-5 6 13
6 -5 2
1 0 1
-11 11 5

Case
Case
Case
Case
Case

Explanation for sample input 1


15:00 GMT+7 is 16:00 GMT+8 in the same day.
Explanation for sample input 2
13:00 GMT-5 is 00:00 GMT+6 one day ahead.
Explanation for sample input 3
02:00 GMT+6 is 15:00 GMT-5 one day behind.

#1:
#2:
#3:
#4:
#5:

16 0
0 1
15 -1
0 0
3 1

Explanation for sample input 3


01:00 GMT+1 is 00:00 GMT+0 in the same day.
Explanation for sample input 5
05:00 GMT-11 is 03:00 GMT+11 one day ahead.

Source: ACM-ICPC Indonesia National Contest 2011 - Qualification Round

ACM-ICPC Indonesia National Contest 2013 - Practice Session

Problem B

Frog in a Bus
Time Limit: 2s

In the Kingdom of Frog, a far far away


country, the citizens use busses to travel
between places. Unlike any city in Indonesia,
busses in Kingdom of Frog are well
organized, they only stop at shelters
specified on their routes. There are several
bus routes and each bus has a number (let's
call it "bus-number") which can be seen from
outside the bus. In each shelter, there is an
information plate which contains a list of bus
number, i.e. a list of busses which will stop at
that particular shelter.
One day Marc -a brave frog knight- hopped
on a bus at a shelter. But when he has been
inside the bus, he just realized that he didn't
check which bus he took at that moment.
Being a brave knight, Marc has quite a high
self-esteem. Therefore, he decided neither
ask nor tell anyone in the bus about this matter. Instead, he tried to deduce which bus he took by observing which shelters are visited by
that bus. From inside the bus, he could read the information plate of each shelter, thus he can learn the list of busses which will stop at
that shelter.
Marc has more brawl than brain, so he needs your help. He will tell you the list of bus-number that he read from information plate in
each shelter, and you should deduce which bus he took.

Input
The first line of input contains an integer T (1 T 100) the number of cases. Each case begins with an integer N (1 N 50) denoting
the number of shelters visited by the bus. The next N lines each begins with an integer M (1 M 10) denoting the number of busnumber written on the information plate of that particular shelter. M integers B i (1 Bi 999) follows denoting the bus-number which bus
stop at that shelter (each number is unique to the shelter).

Output
For each case, output in a line "Case #X: Y" where X is the case number, starting from 1, and Y is either:

The bus-number of bus which he took, i.e. unique possibility, or


"NOT SURE" (without quote) if there's not enough information, i.e. multiple possibilities,
or
"AM I LOST?" (without quote) if there's a contradiction, i.e. no possibility.
Sample Input

Output for Sample Input

3
5

Case #1: 10
Case #2: NOT SURE

5
3
4
2
4
3
2
3
4
3
3
2
3

10 200 95 189 51
143 176 10
143 51 176 10
10 143
188 10 30 51

Case #3: AM I LOST?

100 200
200 150 100
100 150 200 300
50 60 70
70 80
60 80 90

Explanation for the 2nd sample input.


He could be in bus 100 or 200.

Source: ACM-ICPC Indonesia National Contest 2011 - Qualification Round

Das könnte Ihnen auch gefallen