poj 2014
2009/03/06
pku
poj
ひさしぶりにです。Javaです。
自力では解いてないです。
以下、参考。
package p2014;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int w = scanner.nextInt();
if (w == 0)
break;
int now_x = 0;
int x = 0, y = 0;
int now_y = 0;
int max_x = 0;
int max_y = 0;
while (true) {
x = scanner.nextInt();
y = scanner.nextInt();
if (x + y < 0)
break;
if (x + now_x > w) {
now_x = x;
now_y += max_y;
max_y = y;
continue;
}
now_x += x;
if (now_x > max_x)
max_x = now_x;
if (y > max_y)
max_y = y;
}
now_y += max_y;
System.out.println(max_x + " x " + now_y);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int w = scanner.nextInt();
if (w == 0)
break;
int now_x = 0;
int x = 0, y = 0;
int now_y = 0;
int max_x = 0;
int max_y = 0;
while (true) {
x = scanner.nextInt();
y = scanner.nextInt();
if (x + y < 0)
break;
if (x + now_x > w) {
now_x = x;
now_y += max_y;
max_y = y;
continue;
}
now_x += x;
if (now_x > max_x)
max_x = now_x;
if (y > max_y)
max_y = y;
}
now_y += max_y;
System.out.println(max_x + " x " + now_y);
}
}
}
: