DIV1 250pt

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

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

tag:二分,simulation

  1. // BEGIN CUT HERE
  2. /*
  3. * Author: plum rain
  4. * score :
  5. */
  6. /*
  7.  
  8. */
  9. // END CUT HERE
  10. #line 11 "IncredibleMachine.cpp"
  11. #include <sstream>
  12. #include <stdexcept>
  13. #include <functional>
  14. #include <iomanip>
  15. #include <numeric>
  16. #include <fstream>
  17. #include <cctype>
  18. #include <iostream>
  19. #include <cstdio>
  20. #include <vector>
  21. #include <cstring>
  22. #include <cmath>
  23. #include <algorithm>
  24. #include <cstdlib>
  25. #include <set>
  26. #include <queue>
  27. #include <bitset>
  28. #include <list>
  29. #include <string>
  30. #include <utility>
  31. #include <map>
  32. #include <ctime>
  33. #include <stack>
  34.  
  35. using namespace std;
  36.  
  37. #define clr0(x) memset(x, 0, sizeof(x))
  38. #define clr1(x) memset(x, -1, sizeof(x))
  39. #define pb push_back
  40. #define sz(v) ((int)(v).size())
  41. #define all(t) t.begin(),t.end()
  42. #define zero(x) (((x)>0?(x):-(x))<eps)
  43. #define out(x) cout<<#x<<":"<<(x)<<endl
  44. #define tst(a) cout<<a<<" "
  45. #define tst1(a) cout<<#a<<endl
  46. #define CINBEQUICKER std::ios::sync_with_stdio(false)
  47.  
  48. typedef vector<int> vi;
  49. typedef vector<string> vs;
  50. typedef vector<double> vd;
  51. typedef pair<int, int> pii;
  52. typedef long long int64;
  53.  
  54. const double eps = 1e-;
  55. const double PI = atan(1.0)*;
  56. const int inf = / ;
  57.  
  58. class IncredibleMachine
  59. {
  60. public:
  61. vi x, y;
  62. double gao(double g)
  63. {
  64. int n = sz(x);
  65. double v = , sum = ;
  66. for (int i = ; i < n-; ++ i){
  67. double d = sqrt((y[i]-y[i+])*(y[i]-y[i+]) + (x[i]-x[i+])*(x[i]-x[i+]));
  68. double a = g * (y[i] - y[i+]) / d;
  69. double t = (-v + sqrt(v*v+*a*d)) / a;
  70. sum += t; v += a*t;
  71. }
  72. return sum;
  73. }
  74.  
  75. double gravitationalAcceleration(vector <int> X, vector <int> Y, int T){
  76. x = X; y = Y;
  77. int cnt = ;
  78. double l = , r = inf;
  79. while (cnt <= ){
  80. double mid = (l + r) / ;
  81. if (gao(mid) < T) r = mid;
  82. else l = mid;
  83. ++ cnt;
  84. }
  85. return l;
  86. }
  87.  
  88. // BEGIN CUT HERE
  89. public:
  90. void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); }
  91. private:
  92. 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(); }
  93. 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; } }
  94. 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)); }
  95. 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)); }
  96. 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)); }
  97.  
  98. // END CUT HERE
  99.  
  100. };
  101.  
  102. // BEGIN CUT HERE
  103. int main()
  104. {
  105. // freopen( "a.out" , "w" , stdout );
  106. IncredibleMachine ___test;
  107. ___test.run_test(-);
  108. return ;
  109. }
  110. // END CUT HERE

DIV1 500pt

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

SRM 440(1-250pt, 1-500pt)的更多相关文章

  1. topcoder srm 440 div1

    problem1 link 二分答案,然后计算总时间.跟$T$比较确定要增大答案还是减小答案. problem2 link 可以看作是以‘*’所在位置为根的树.所以每个非根节点都有一个父节点. 那么每 ...

  2. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  3. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  4. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  5. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  6. topcoder srm 553

    div1 250pt: 题意:... 解法:先假设空出来的位置是0,然后模拟一次看看是不是满足,如果不行的话,我们只需要关心最后栈顶的元素取值是不是受空白处的影响,于是还是模拟一下. // BEGIN ...

  7. topcoder srm 552

    div1 250pt: 题意:用RGB三种颜色的球摆N层的三角形,要求相邻的不同色,给出RGB的数量,问最多能摆几个 解法:三种颜色的数量要么是全一样,要么是两个一样,另外一个比他们多一个,于是可以分 ...

  8. topcoder srm 551

    div1 250pt 题意:一个长度最多50的字符串,每次操作可以交换相邻的两个字符,问,经过最多MaxSwaps次交换之后,最多能让多少个相同的字符连起来 解法:对于每种字符,枚举一个“集结点”,让 ...

  9. topcoder srm 550

    div1 250pt: 题意:有个机器人,从某一点出发,他只有碰到地形边缘或者碰到走过的点时才会改变运动方向,然后接着走,现在给出他的运动轨迹,判断他的运动是否合法,如果合法的话,那么整个地形的最小面 ...

随机推荐

  1. 数据库性能高校:CPU使用过高(下)

    CPU使用率过高的常见原因 查询优化器会尽量从CPU,IO和内存资源成本最小的角度,找到最高效的数据访问方式.如果没有正确的索引,或者写的语句本身就会忽略索引, 又或者不准确的统计信息等情况下,查询计 ...

  2. python中文问题汇总

    1.中文路径 #-*-coding:utf-8-*- path=ur'E:\accumulate\Python\语法\08输入和输出\1.txt' #python内部使用的是unicode,不加前缀u ...

  3. Quartz-2D绘图之路径(Paths)详解

    在上篇文章中,我们简单的理解了绘图上下文,今天我们来认识一下Quartz-2D中另一个重要的概念,路径(Paths). 一.理解路径 路径定义了一个或多个形状,或是子路径.一个子路径可由直线,曲线,或 ...

  4. Hadoop学习第一天

    1.hadoop量大,数目多. 存储:分布式,集群的概念,管理(主节点.从节点),HDFS. 分析:分布式.并行.离线计算框架,管理(主节点.从节点),MapReduce. 来源:GFS->HD ...

  5. python入门笔记第一天

    查询acsii命令 ord(‘A’) 导入模块python执行系统命令显示文件.查找文件方法1import osa = os.popen('目标').read()a 解释output = os.pop ...

  6. Centos7 修改运行级别

    systemd使用比sysvinit的运行级别更为自由的target概念作为替代 第三运行级: multi-user.target 第五运行级: graphical.target   #前者是符号链接 ...

  7. ASP.NET MVC轻教程 Step By Step 7——改进Write动作方法

    在上一节我们使用强类型视图改进Write视图获得更好的智能感知和代码重构,现在可以进一步的改进动作方法. Step 1. 数据模型绑定 在Save方法中我们使用Request来获取表单传送的值,其实可 ...

  8. 关于Memcache使用的工具类

    分布式缓存有它自己的好处 . 下面的 ConstValue.sessionId  是一个常量 public static readonly string sessionId = "sessi ...

  9. 构建微服务:Spring boot

    构建微服务:Spring boot 在上篇文章构建微服务:Spring boot 提高篇中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jp ...

  10. 我们说的oc是动态运行时语言是什么意思?

    1.KVC和KVO区别,分别在什么情况下使用?  答:KVC(Key-Value-Coding) KVO(Key-Value-Observing)理解KVC与KVO(键-值-编码与键-值-监看) 当通 ...