/* VIM: let g:lcppflags="-std=c++11 -O2 -pthread" VIM: let g:wcppflags="/O2 /EHsc /DWIN32" */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; typedef std::vector vec; void check(bool b) { if (!b) std::cerr << "error" << std::endl; } template std::string to_string( T t ){ std::stringstream ss; ss << t; return ss.str(); } /* */ auto solve_puzzle(std::istream& is) { long long n, d, k, s; double mt = 0; is >> d >> n; for ( auto i = 0; i < n; ++i ) { is >> k >> s; double t = double(d - k) / s; mt = std::max( mt, t); } return d / mt; } void read_input_and_solve( std::istream& is, std::ostream& os ) { srand((unsigned)time(NULL)); int puzzle_count; is >> puzzle_count; is.ignore(std::numeric_limits::max(), '\n'); for (int i = 1; i <= puzzle_count; i++) { os << "Case #" << i << ": "; auto r = solve_puzzle(is); os << std::fixed << r << std::endl; } } int main(int argc, char * argv[]) { try{ if ( *++argv ) { std::ifstream ifs(*argv); read_input_and_solve( ifs, std::cout ); } else { read_input_and_solve( std::cin, std::cout ); } return 0; } catch (const std::exception& e) { std::cerr << std::endl << "std::exception(\"" << e.what() << "\")." << std::endl; return 2; } catch (...) { std::cerr << std::endl << "unknown exception." << std::endl; return 1; } }