zoukankan      html  css  js  c++  java
  • HDU 5935 Car

    题意:

    一个人在开车 一个交警在抓拍

    给了你n个数字 是每次抓拍时候的位置

    这个人一直是不减速的 问从0到最后给你的那个点最短时间是多少

    思路:

    我们倒着推 把最后一段当作一秒跑完的 并且把这个值设为当前速度

    如果前面有一段不是当前速度的整数倍 就更新当前速度

    题不是很难 但是坑点比较多

     1 #include<bits/stdc++.h>
     2 #define cl(a,b) memset(a,b,sizeof(a))
     3 #define debug(a) cerr<<#a<<"=="<<a<<endl
     4 using namespace std;
     5 typedef long long ll;
     6 typedef pair<int,int> pii;
     7 
     8 const int maxn=1e5+10;
     9 
    10 int a[maxn];
    11 
    12 int main()
    13 {
    14     int T,cas=1;
    15     scanf("%d",&T);
    16     while(T--)
    17     {
    18         int n;
    19         scanf("%d",&n);
    20         a[0]=0;
    21         for(int i=1;i<=n;i++)
    22         {
    23             scanf("%d",&a[i]);
    24         }
    25         ll ans=0; //第一个坑点就是ans会爆int 要用ll
    26         double mx=a[n]-a[n-1];//第二个坑点就是要用double来记录最大速度
    27         for(int i=n;i>=1;i--)
    28         {
    29             double dis=(a[i]-a[i-1])*1.0;
    30             int t=dis/mx;
    31             if(dis/t==mx)//这个也不算坑点 因为抓拍不是一秒一张 所以是整数倍就可以了
    32             {
    33                 ans+=t;
    34             }
    35             else
    36             {
    37                 ans+=(t+1);
    38                 mx=dis/(t+1);
    39             }
    40         }
    41         printf("Case #%d: %lld
    ",cas++,ans);
    42     }
    43     return 0;
    44 }/*
    45 
    46 1
    47 3
    48 6 11 21
    49 
    50 */
  • 相关阅读:
    安装Joomla!3
    keepalived + lvs
    systemd 服务介绍
    lvs 进阶 第二章
    lvs 初始 第一章
    iptables 最终 第四章
    bind 笔记
    iptables 扩展匹配 第三章
    iptables 认识 第二章
    iptables 初见 第一章
  • 原文地址:https://www.cnblogs.com/general10/p/7359860.html
Copyright © 2011-2022 走看看