• ZOJ 2763 Prison Break


    题意:一群人要越狱,要用绳子荡过一条沟,给你初速度和体重,和对岸墙的高度,先做单摆运动后是斜抛,当高度和墙同高时松手斜抛。问你最后能成功越狱的有谁名字按字典序输出。

    View Code
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <cstdio>
    #include <math.h>
    #include <vector>
    using namespace std;
    #define inf 1000000000
    #define eps 1e-8
    #define G 9.8
    
    int dd(double x,double y){ return fabs(x-y)<eps;} // x==y
    int dy(double x,double y){ return x>y+eps;}   // x>y
    int xy(double x,double y){ return x<y-eps;}   //x<y
    int dyd(double x,double y){ return x>y-eps;}  //x>=y
    int xyd(double x,double y){ return x<y+eps;}  //x<=y
    
    int main() {
        int m;
        double L,W,H,v,w,vx,vy,wei;
        string name;
        while(scanf("%d",&m) == 1) {
            vector<string> ans(0);
            scanf("%lf%lf%lf",&L,&W,&H);
            while(m--) {
                cin >> name;
                scanf("%lf%lf",&wei,&v);
                if(dy( H, L)) 
                    continue;
                w = sqrt(H*(2.0*L-H));
                if(dy( w, W)) //撞墙了!
                    continue;
                if(dy( 2.0*G*H, v*v))//到不了这高度
                    continue;
                v = sqrt(fabs(v*v - 2.0*G*H));
                double vx = v * (L-H) / L;
                double vy = v * w / L;
                w += 2.0*vx * vy / G;
                if(xy( w, W)) 
                    continue;
                ans.push_back(name);
            }
            sort(ans.begin(), ans.end());
            cout << ans.size() << endl;
            for(int i = 0; i < ans.size(); ++i)
                cout << ans[i] << endl;
        }
        return 0;
    }

    注:vector的快速排序,和精度处理

  • 相关阅读:
    hrbust1279
    U盘快捷方式中毒处理办法
    计算几何
    poj1113
    凸包模版
    STL容器
    HDU2048
    HDU2047
    HDU2045
    python面试题总结
  • 原文地址:https://www.cnblogs.com/gray035/p/2964908.html
Copyright © 2020-2023  润新知