SRM 440(1-250pt, 1-500pt)

时间:2024-08-15 10:36:20

DIV1 250pt

题意:小球从一段折线斜坡上滚下来,告诉所用时间,求重力加速度。

解法:二分答案模拟即可。

tag:二分,simulation

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "IncredibleMachine.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <set>
#include <queue>
#include <bitset>
#include <list>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; class IncredibleMachine
{
public:
vi x, y;
double gao(double g)
{
int n = sz(x);
double v = , sum = ;
for (int i = ; i < n-; ++ i){
double d = sqrt((y[i]-y[i+])*(y[i]-y[i+]) + (x[i]-x[i+])*(x[i]-x[i+]));
double a = g * (y[i] - y[i+]) / d;
double t = (-v + sqrt(v*v+*a*d)) / a;
sum += t; v += a*t;
}
return sum;
} double gravitationalAcceleration(vector <int> X, vector <int> Y, int T){
x = X; y = Y;
int cnt = ;
double l = , r = inf;
while (cnt <= ){
double mid = (l + r) / ;
if (gao(mid) < T) r = mid;
else l = mid;
++ cnt;
}
return l;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arr0[] = {,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; double Arg3 = 9.807692307692307; verify_case(, Arg3, gravitationalAcceleration(Arg0, Arg1, Arg2)); }
void test_case_1() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; double Arg3 = 26.743031720603582; verify_case(, Arg3, gravitationalAcceleration(Arg0, Arg1, Arg2)); }
void test_case_2() { int Arr0[] = {,,}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arr1[] = {,,}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[]))); int Arg2 = ; double Arg3 = 1.1076837407708007; verify_case(, Arg3, gravitationalAcceleration(Arg0, Arg1, Arg2)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
// freopen( "a.out" , "w" , stdout );
IncredibleMachine ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

DIV1 500pt

裸的高斯消元求解概率dp。。。。。。