• Codeforces 339B:Xenia and Ringroad(水题)


    time limit per test : 2 seconds
    memory limit per test : 256 megabytes
    input : standard input
    output : standard output

    Xenia lives in a city that has nn houses built along the main ringroad. The ringroad houses are numbered 11 through nn in the clockwise order. The ringroad traffic is one way and also is clockwise.

    Xenia has recently moved into the ringroad house number 11. As a result, she’s got m things to do. In order to complete the ii-th task, she needs to be in the house number aia_i and complete all tasks with numbers less than ii. Initially, Xenia is in the house number 11, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.

    Input

    The first line contains two integers nn and mm (2n105,1m105)(2 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^5). The second line contains mm integers a1,a2,...,am(1ain)a_1, a_2, ..., a_m (1 ≤ a_i ≤ n). Note that Xenia can have multiple consecutive tasks in one house.

    Output

    Print a single integer — the time Xenia needs to complete all tasks.

    Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

    Examples

    input
    4 3
    3 2 3
    output
    6
    input
    4 3
    2 3 3
    output
    2

    Note

    In the first test example the sequence of Xenia’s moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.

    题意

    nn个点围成的圆,每个点编号11~nn,要求第ii个点的任务必须在aia_i点完成,并且必须按照顺序去完成任务。计算完成所有任务需要花费的最小时间(移动一个点花费时间为11

    嘤嘤嘤,题意读了一年,真的是废了

    Code

    /*************************************************************************
    
    	 > Author: WZY
    	 > School: HPU
    	 > Created Time:   2019-03-26 15:36:37
    	 
    ************************************************************************/
    #include <cmath>
    #include <cstdio>
    #include <time.h>
    #include <cstring>
    #include <limits.h>
    #include <iostream>
    #include <algorithm>
    #include <random>
    #include <iomanip>
    #include <map>
    #include <set>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <string>
    #include <random>
    #define ll long long
    #define ull unsigned long long
    #define lson o<<1
    #define rson o<<1|1
    #define ms(a,b) memset(a,b,sizeof(a))
    #define SE(N) setprecision(N)
    #define PSE(N) fixed<<setprecision(N)
    #define bug cout<<"-------------"<<endl
    #define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"
    "
    #define LEN(A) strlen(A)
    const double E=exp(1);
    const double eps=1e-9;
    const double pi=acos(-1.0);
    const int mod=1e9+7;
    const int maxn=1e6+10;
    const int maxm=1e3+10;
    const int moha=19260817;
    const int inf=1<<30;
    const ll INF=1LL<<60;
    using namespace std;
    inline void Debug(){cerr<<'
    ';}
    inline void MIN(int &x,int y) {if(y<x) x=y;}
    inline void MAX(int &x,int y) {if(y>x) x=y;}
    inline void MIN(ll &x,ll y) {if(y<x) x=y;}
    inline void MAX(ll &x,ll y) {if(y>x) x=y;}
    template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
    	cerr<<arg<<"";Debug(rest...);}
    int a[maxn];
    int vis[maxn];
    int main(int argc, char const *argv[])
    {
    	ios::sync_with_stdio(false);cin.tie(0);
    	cout.precision(20);
    	#ifndef ONLINE_JUDGE
    	    freopen("in.txt", "r", stdin);
    	    freopen("out.txt", "w", stdout);
    		srand((unsigned int)time(NULL));
    	#endif
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=m;i++)
    		cin>>a[i];
    	ll ans=0;
    	int res=1;
    	vis[res]=1;
    	ans+=a[1]-1;
    	while(res<m)
    	{
    		if(a[res]>a[res+1])
    			ans+=(n-a[res])+a[res+1];
    		else if(a[res]==a[res+1])
    		{
    			res++;
    			continue;
    		}
    		else
    			ans+=(a[res+1]-a[res]);
    		res++;
    	}
    	cout<<ans<<endl;
    	#ifndef ONLINE_JUDGE
    	    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s.
    ";
    	#endif
    	return 0;
    }
    
  • 相关阅读:
    开发者和设计师:为何我们不能好好相处?(转载)
    PHP ACCESS
    来自腾讯的session跨域,跨服代码
    php大括号妙用。
    php mysql 记录集的操作
    开始我的代码笔记
    收藏一个php用的一个页码按钮类
    修改过后的数字英文字符生成图片代码
    搜藏一点php session 常用方法
    php包含漏洞收集程序代码
  • 原文地址:https://www.cnblogs.com/Friends-A/p/11054962.html
Copyright © 2020-2023  润新知