Google Code Jam 2017

This commit is contained in:
2017-05-16 22:18:46 +01:00
parent a9cee6e867
commit 951f9f63c7
35 changed files with 27077 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
/*
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
*/
#include <assert.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <exception>
#include <stdexcept>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <string>
#include <memory>
#include <functional>
#include <algorithm>
#include <utility>
#include <limits>
#include <math.h>
typedef long long ll;
typedef std::vector<ll> vec;
void check(bool b) { if (!b) std::cerr << "error" << std::endl; }
template <typename T>
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<std::streamsize>::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;
}
}