P1007 zhuqiao and p1007 zhuqiao

Source: Internet
Author: User

P1007 zhuqiao and p1007 zhuqiao
Background

The war has entered a critical time. You are the transport chief and are leading the transportation troops to deliver materials along the way. A transportation task is as boring as a question. If you want to find some excitement, you can order your soldiers to enjoy the scenery on a wooden bridge ahead, and you will stay under the bridge to enjoy the soldiers. The soldiers were very angry because the bridge was very narrow and could only accommodate one person. If two people face each other and face each other on the bridge, they will bypass each other. Only one person can go back to the bridge and let the other person pass the bridge first. However, multiple people can stay in the same location at the same time.

Description

Suddenly, you received a message from the command center, and the enemy's bomber was flying towards your render bridge! To ensure security, your troops must remove the zhuqiao. The length of the bridge is L, and soldiers can only stay at the place where the coordinates are integers. The speed of all soldiers is 1, but when a soldier arrives at the coordinates of 0 or L + 1, he leaves the zhuqiao.

Every soldier has an initial direction. They will walk in this direction at a constant speed and will not change their direction in the middle. However, if the two soldiers met each other face to face, they could not pass each other, so they turned and walked on separately. Turning around does not require any time.

You cannot control your soldiers because of your previous anger. Even you don't even know the direction each soldier initially faces. Therefore, you want to know the minimum time required by your troops to evacuate all of them. In addition, the headquarters is also arranging to block the enemy's attack. Therefore, you still need to know how much time your troops will need at most before they can all be evacuated from the zhuqiao.

Input/Output Format Input Format:

The first line is an integer L, indicating the length of the bridge. The coordinates on the bridge are 1... L

Row 2: an integer N, indicating the number of soldiers left on the bridge at the beginning

Row 3: There are N integers representing the initial coordinates of each soldier.

Output Format:

There is only one row, and two integers are output, indicating the minimum time and maximum time for troops to withdraw from the zhuanqiao. The two integers are separated by a space character.

Input and Output sample Input example #1:
421 3
Output sample #1:
2 4
Description

At the beginning, no two soldiers were in the same coordinate.

Data range: N <= L <= 1000.

After every soldier turns, we can see two soldiers exchange identities and continue

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 int read(int & n) 8 { 9     char c='.';int x=0,flag=0;10     while(c<'0'||c>'9')11     {c=getchar();  if(c=='-')flag=1; }12     while(c>='0'&&c<='9')13     {x=x*10+(c-48);c=getchar();}14     if(flag==1)n=-x;else n=x;15 }16 const int MAXN=10001;17 int a[MAXN];18 int n,l;19 int minn,maxn;20 int main()21 {22     read(l);read(n);23     for(int i=1;i<=n;i++)24     {25         read(a[i]);26         minn=max(minn,min(a[i],(l-a[i])+1)),27         maxn=max(maxn,max(a[i],(l-a[i])+1));28     }29         30     printf("%d %d",minn,maxn);31     return 0;32 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.