Saturday, January 29, 2011

ACM:POJ:1003

Problem:
http://poj.org/problem?id=1003


Solution: (reminder: again this is not the optimal solution, it's a solution that was accepted by the judge server!)


import java.util.*;

public class Main {

public static void main(String args[]) throws Exception {
Scanner cin = new Scanner(System.in);

float d = 0;
int n = 1;
float f = 0;
int fin = 0;

while (cin.hasNextFloat()) {

d = 0;
n = 1;
f = 0;
fin = 0;

d = cin.nextFloat();

while (true) {

if (d == (float) 0)
break;

f = f + (float) (1 / (float) (n + 1));

if (f <= d) fin = n; else { System.out.println(n + " card(s)"); break; } n++; } } } }

No comments:

Post a Comment