美文网首页
CodeFoeces-1257A

CodeFoeces-1257A

作者: ss5smi | 来源:发表于2019-11-22 17:04 被阅读0次

题目

原题链接:A. Two Rival Students

题意

已知a和b在长位n的序列中的位置,有x次交换临近两人位置的操作,求a和b最大的距离。

代码

#include<stdio.h>
int cal(int a,int b){return (a>b?a:b)-(a>b?b:a);}
int main(){
    int t,n,x,a,b;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d %d %d",&n,&x,&a,&b);
        int s = cal(a,b), l = cal(n,(a>b?a:b)) + cal(1,(a>b?b:a));
        printf("%d\n",s + (l>x?x:l) );
    } 
    return 0;
} 

相关文章

  • CodeFoeces-1257A

    题目 原题链接:A. Two Rival Students 题意 已知a和b在长位n的序列中的位置,有x次交换临近...

网友评论

      本文标题:CodeFoeces-1257A

      本文链接:https://www.haomeiwen.com/subject/quhqwctx.html