zoukankan      html  css  js  c++  java
  • hdu 1275纯数学题

    找出足够的相遇或追及的时间,排个序输出就可以了。

    /*
     * hdu1275/win.cpp
     * Created on: 2012-10-23
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    typedef struct Node{
        double t;
        double dis;
        Node() {
            dis = t = 0;
        }
        Node(double tt, double dd) {
            t = tt;
            dis = dd;
        }
    }Node;
    inline bool operator<(const Node &n1, const Node &n2) {
        return n1.t < n2.t;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T, n;
        double S, v1, v2, v3, v4;
        scanf("%d", &T);
        while(T--) {
            set<Node> myset;
            scanf("%lf%lf%lf%d", &S, &v1, &v2, &n);
            v3 = v1 + v2;
            v4 = fabs(v1 - v2);
            for(int k = 1; k < 3000; k += 2) {
                double t = k * S / v3;
                double dis = t * v1;
                dis = dis - (int)(dis / S) * S;
                if(2 * dis > S) {
                    dis = S - dis;
                }
                myset.insert(Node(t, dis));
                t = k * S / v4;
                dis = t * v1;
                dis = dis - (int)(dis / S) * S;
                if(2 * dis > S) {
                    dis = S - dis;
                }
                myset.insert(Node(t, dis));
            }
            set<Node>::iterator it = myset.begin();
            while(n-- > 1) {
                it++;
            }
            printf("Time=%.3f Dist=%.3f\n", (*it).t, (*it).dis);
        }
        return 0;
    }
  • 相关阅读:
    Linux就该这么学(第一天)
    在虚拟机中使用Git
    Myeclipse的一些快捷键整理(转)
    SpringMVC框架应用
    动态网页开发基础
    jsp数据交互(二)
    jsp数据交互(一)
    复习数据结构(基于大话数据结构)
    IO及NIO的总结
    学习正则表达式笔记
  • 原文地址:https://www.cnblogs.com/moonbay/p/2736111.html
Copyright © 2011-2022 走看看