A.Two Rival Students
题目:两个竞争的学生##
链接:(两个竞争的对手)[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的更多相关文章
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- 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 ...
- 【CF1257A】Two Rival Students【思维】
题意:给你n个人和两个尖子生a,b,你可以操作k次,每次操作交换相邻两个人的位置,求问操作k次以内使得ab两人距离最远是多少 题解:贪心尽可能的将两人往两边移动,总结一下就是min(n-1,|a-b| ...
- Educational Codeforces Round 76 (Rated for Div. 2)
传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...
- Codeforces 1256A 1257A
题目链接:https://codeforces.com/problemset/problem/1256/A A. Payment Without Change time limit per test ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- Advice for students of machine learning--转
原文地址:http://www.mimno.org/articles/ml-learn/ written by david mimno One of my students recently aske ...
- RPCL(Rival Penalized Competitive Learning)在matlab下的实现
RPCL是在线kmeans的改进版,相当于半自动的选取出k个簇心:一开始设定N个簇心,N>k,然后聚类.每次迭代中把第二近的簇心甩开一段距离. 所谓在线kmeans是就是,每次仅仅用一个样本来更 ...
- HDOJ 2444 The Accomodation of Students
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
随机推荐
- ASP.NET Core 1.0: 指定Default Page
前不久写过一篇Blog<指定Static File中的文件作为Default Page>,详细参见链接. 然而,今天偶然发现了一个更加简洁的方法,直接使用Response的Redirect ...
- 实现两个数字的交换(C语言)
int num1=10; int num2=20; //1.简单的数学方法实现数字交换 num1=num1+num2;//num1=30 num2=num1-num2;//num2=10 num1=n ...
- linux日常笔记(1)
1.SELlinux SELinux是 美国国家安全局 (NSA) 对于 强制访问控制的实现 =>可以使root受限的权限 关闭SELinux=>修改配置文件,永久生效; sed -i ' ...
- 编写 Dockerfile 最佳实践
官方仓库虽然有数十万计的免费镜像,但大多数无法直接满足公司业务需求,这就需要我们自己去定制镜像了. Docker通过Dockerfile自动构建镜像,Dockerfile是一个包含用于组建镜像的文本文 ...
- 控制层传递参数到jsp页面,jsp页面进行接收
在java代码中,控制层方法如下(采用model,还有其他方式) public String mysave(MyTreeMould myTreeMould, Model model) {...... ...
- ES6 Map 原理
ES6的Map的键可以是任意的数据结构,并且不重复. 那么map的底层原理是啥呢? Map利用链表,hash的思想来实现. 首先,Map可以实现删除,而且删除的数据可以是中间的值.而链表的优势就是在中 ...
- connected datagram 与TCP连接的区别
TCP连接流程是TCP协议的一部分,需要经过三次握手.而connected datagram虽然使用了socket的同样的函数connect,但是UDP协议并不包含连接流程,也就是UDP实际上并没有真 ...
- 微信小程序使用 ECharts 实现数据可视化
微信小程序使用 ECharts 显示图表 首先创建微信小程序 这里就不再赘述 下载 GitHub 上的 ecomfe/echarts-for-weixin 下载后解压,打开文件夹,里面的 ec-can ...
- OpenStack集成ceph
openstack组件集成ceph OpenStack集成ceph详细过程可以查看ceph官方文档:ceph document OpenStack Queens版本,1台控制节点controller, ...
- linux搭建ftp出错汇总
重启vsftpd出现”500 OOPS: vsftpd: cannot open config file:restart” 2008-05-09 21:33 进到/etc/init.d/目录 输入: ...