zoukankan      html  css  js  c++  java
  • 独木桥

    https://www.luogu.org/problemnew/show/P1007

    不用考虑七七八八的换头,每个士兵其实都是一样的,所以当他们遇见时,就当直接传过去||或者灵魂交换。//哈哈,喜欢这种高空俯视视角。

    所以就直接求向左走和向右走的最大小值就行

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 #include<stdlib.h>
     8 #define mem(a) memset(a,0,sizeof(a))
     9 const double pi=acos(-1.0);
    10 using namespace std;
    11 int main()
    12 {
    13   int n,l,p;
    14   cin>>l;
    15   cin>>n;
    16   int ma,mi;
    17   ma=mi=0;
    18   for(int i=0;i<n;i++)
    19   {
    20       cin>>p;
    21       ma=max(ma,max(l-p+1,p));
    22  //每读取一个数都判断一次,逐步加,ma一定是当前最久的士兵的步数
    23       mi=max(mi,min(l-p+1,p));
    24  //前面是max是因为要考虑士兵最快中的最慢
    25   }
    26   cout<<mi<<" "<<ma<<endl;
    27   return 0;
    28 }
    View Code
  • 相关阅读:
    01_计算机基础
    09_哈希表
    08_查找算法
    Swagger使用
    Thymeleaf代码实例
    Spring boot代码实例
    Spring mvc代码实例
    Hibernate代码实例
    Mysql JDBC代码实例
    Mybatis代码实例
  • 原文地址:https://www.cnblogs.com/XXrll/p/10197863.html
Copyright © 2011-2022 走看看