当前位置:网站首页>P1007 single wooden bridge (simple greed)

P1007 single wooden bridge (simple greed)

2021-08-10 08:03:59 wx6110fa547fd20

P1007 Single-plank bridge ( Simple greed )

  Subject portal

The question :n A soldier is growing up for L Single-plank bridge , The starting direction of each soldier is unknown , When the two soldiers met, they turned and walked away , Ask all soldiers to leave for the least and most time

Ideas : obviously , The minimum time is : The maximum value of all soldiers taking the optimal path . The maximum time is : The maximum value of all soldiers taking the worst path .

#include<bits/stdc++.h>
using namespace std;
int main(){
	int l,n;
	cin>>l>>n;
	int a[n],mn=0,mx=0;
	for(int i=0;i<n;i++) cin>>a[i],mn=max(min(a[i],l+1-a[i]),mn),mx=max(mx,max(a[i],l+1-a[i]));
	printf("%d %d\n",mn,mx);
	return 0;
} 

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205522Z.html

随机推荐