CPC23四 A.

来源:互联网 发布:池州安广网络安装人员 编辑:程序博客网 时间:2024/05/23 12:00
A.Running Around Park
Time Limit: 10000 MS Memory Limit: 65536 K
Total Submit: 72 (52 users) Total Accepted: 53 (52 users) Special Judge: No
Description

Alice went jogging around the park yesterday. There is a circular track around the park, and Alice's house is right next to the track. Alice ran in the clockwise direction. She both started and ended her run at her house. In other words, she completed some positive number of full laps.

There are N trees along the track. The trees are numbered 1 through N in the order in which Alice encounters them when running a single lap. You are given the int N.

Alice remembers some trees she saw during her run. She remembers them in the order in which she encountered them. You are given this information as a int[] d.

For example, d={6,6,1} has the following meaning:

Alice started running.

After some time she encountered the tree number 6.

After some more time she encountered the tree number 6.

Even later she encountered the tree number 1.

Compute and return the smallest possible number of laps Alice completed.
Input

For each test data. The first line contains two number N and dN.

The second line contains dN number, the ith of them is di.

- N will be between 2 and 50, inclusive.

- dN will between 1 and 50.

- Each element of d will be between 1 and N, inclusive.
Output

For each test, compute and return the smallest possible number of laps Alice completed.
Sample Input

3 3

1 2 3

24 2

6 6

3 3

3 2 1


50 10

1 3 5 7 9 2 4 6 8 10
Sample Output

1

2

3

2



解题思路:

        题意是一个人绕着田径场跑圈,树从1~n标号,给出沿途遇见的树的标号,问这个人最后总共跑了多少圈。

        如果当前树的标号小于等于前一个树的标号,那么圈数加1.



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int a[100001];int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n , m;    while(~scanf("%d%d",&n,&m))    {        for(int i = 0 ;i  < m ; i++)        {            scanf("%d",&a[i]);        }        int cnt = 1;        for(int i = 1 ;  i < m ; i ++)        {            if(a[i] <= a[i-1])                cnt++;        }        printf("%d\n",cnt);    }}


0 0