题目:两个竞争的学生##

链接:(两个竞争的对手)[https://codeforces.com/contest/1257/problem/A]

题意:有n个学生排成一行。其中有两个竞争的学生。第一个学生在位置a,第二个学生在位置b,位置从左往右从1到n编号。

你的目的是在经过x次交换后,他们之间的距离最大。(每次交换都是交换相邻的两个学生)

分析:

1.答案是不可能大于n - 1的

2.两者之间的距离可以通过交换增加x,只要答案小于n - 1

因此,取两者最小值就是答案

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std;
const int INF = 0x3f3f3f3f;
int main()
{
int t;
scanf("%d", &t);
int n, x, a, b;
while (t--)
{
scanf("%d%d%d%d", &n, &x, &a, &b); int ans = INF;
ans = min(n - 1, abs(a - b) + x);
printf("%d\n", ans);
} return 0;
}

A.Two Rival Students的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  2. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students

    You are the gym teacher in the school. There are nn students in the row. And there are two rivalling ...

  3. 【CF1257A】Two Rival Students【思维】

    题意:给你n个人和两个尖子生a,b,你可以操作k次,每次操作交换相邻两个人的位置,求问操作k次以内使得ab两人距离最远是多少 题解:贪心尽可能的将两人往两边移动,总结一下就是min(n-1,|a-b| ...

  4. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  5. Codeforces 1256A 1257A

    题目链接:https://codeforces.com/problemset/problem/1256/A A. Payment Without Change time limit per test ...

  6. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  7. Advice for students of machine learning--转

    原文地址:http://www.mimno.org/articles/ml-learn/ written by david mimno One of my students recently aske ...

  8. RPCL(Rival Penalized Competitive Learning)在matlab下的实现

    RPCL是在线kmeans的改进版,相当于半自动的选取出k个簇心:一开始设定N个簇心,N>k,然后聚类.每次迭代中把第二近的簇心甩开一段距离. 所谓在线kmeans是就是,每次仅仅用一个样本来更 ...

  9. HDOJ 2444 The Accomodation of Students

    染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

随机推荐

  1. 网络编程--UDP通讯

    UTP传输 public class Send1 { public static void main(String[] args) throws Exception { Scanner sc=new ...

  2. js的split()和join()的用法

    split() 方法用于把一个字符串分割成字符串数组.split[splɪt]:vt. 分离:使分离:劈开:离开:分解 stringObject.split(separator,howmany) se ...

  3. nyoj 55-懒省事的小明(priority_queue)

    55-懒省事的小明 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:8 submit:62 题目描述:       小明很想吃果子,正好果园果子熟了. ...

  4. nyoj 61-传纸条(一)(双向dp)

    61-传纸条(一) 内存限制:64MB 时间限制:2000ms Special Judge: No accepted:8 submit:37 题目描述: 小渊和小轩是好朋友也是同班同学,他们在一起总有 ...

  5. 【Vue | ElementUI】Vue离开当前页面时弹出确认框实现

    Vue离开当前页面时弹出确认框实现 1. 实现目的 在某种业务场景下,用户不允许跳转到其他页面.于是,需要在用户误操作或者是点击浏览器跳转时提示用户. 2. 实现原理 使用路由守卫beforeRout ...

  6. 领扣(LeetCode)回文链表 个人题解

    请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶:你能否用 O(n) 时间复杂 ...

  7. windows 10上源码编译dlib教程 | compile dlib on windows 10

    本文首发于个人博客https://kezunlin.me/post/654a6d04/,欢迎阅读! compile dlib on windows 10 Series Part 1: compile ...

  8. Android 获取 SHA1值3步完成

    未经允许,禁止

  9. TypeError: Cannot read property '_t' of undefined (VUE + ElementUI + i18n)

    在使用vue的ElementUI库,在多语言时报错: TypeError: Cannot read property '_t' of undefined 错误是在点菜单栏时随机抛出的,F12抓不到,只 ...

  10. 音视频入门-14-JPEG文件格式详解

    * 音视频入门文章目录 * JPEG 文件格式解析 JPEG 文件使用的数据存储方式有多种.最常用的格式称为 JPEG 文件交换格式(JPEG File Interchange Format,JFIF ...