【CF1257A】Two Rival Students【思维】
题意:给你n个人和两个尖子生a,b,你可以操作k次,每次操作交换相邻两个人的位置,求问操作k次以内使得ab两人距离最远是多少
题解:贪心尽可能的将两人往两边移动,总结一下就是min(n-1,|a-b|+x)
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int T;
int n,m,a,b;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&a,&b);
if(a>b)swap(a,b);
int t=min(a-,m);
a-=t;m-=t;
t=min(n-b,m);
b+=t;m-=t;
printf("%d\n",b-a);
}
return ;
}
【CF1257A】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 ...
- A.Two Rival Students
题目:两个竞争的学生 链接:(两个竞争的对手)[https://codeforces.com/contest/1257/problem/A] 题意:有n个学生排成一行.其中有两个竞争的学生.第一个学生 ...
- 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 ...
- T - Posterized(贪心思维)
Description Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked hi ...
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序
用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html 目录 马桶排序(令人 ...
- 计算机程序的思维逻辑 (60) - 随机读写文件及其应用 - 实现一个简单的KV数据库
57节介绍了字节流, 58节介绍了字符流,它们都是以流的方式读写文件,流的方式有几个限制: 要么读,要么写,不能同时读和写 不能随机读写,只能从头读到尾,且不能重复读,虽然通过缓冲可以实现部分重读,但 ...
随机推荐
- 130、TensorFlow操作多个计算图
# Programming with multiple graphs # 当训练一个模型的时候一个常用的方式就是使用一个图来训练你的模型 # 另一个图来评价和计算训练的效果 # 在许多情况下前向计算和 ...
- 123、TensorFlow的Job
# 如果你在分布式环境中部署TensorFlow # 你或许需要指定job name和task ID # 来将变量放置在参数服务器上 # 将操作放在worker job import tensorfl ...
- Wildfly安装以及集成idea(mac)
文章目录 Linux发布运行 下载 集成idea Linux发布运行 首先说一下在linux环境,只需要将war包上传到wildfly-8.2.0.Final/standalone/deploymen ...
- win10 文件管理器频繁卡死
参考: https://www.xitmi.com/1589.html
- 2019/11/09 TZOJ
1001 Interesting Integers http://www.tzcoder.cn/acmhome/problemdetail.do?&method=showdetail& ...
- JAVA线程初体验
线程的创建 线程的启动和停止 /** * 演员类 继承Thread类 * @author Administrator * */ public class Actor extends Thread { ...
- spring-第十四篇之资源访问Resource接口
1.Resource接口提供的主要方法 1>getInputStream():定位并打开资源,返回资源对应的输入流.每次调用都返回新的输入流.调用者必须负责关闭输入流. 2>isOpen( ...
- python学习第二十七天函数的return返回值
python函数返回值用的return ,函数遇到return 结束函数运行过程,终止程序,不论后面还有多少个输出,都终止本次函数,所有一定要慎重用return 1,函数return用法 def go ...
- weBDrriver API接口方法小记
3.2.1 输入框(text field or textarea) 找到输入框元素:WebElement element = driver.findElement(By.id("passwd ...
- C# 字符串的拆分
string str = "ABCD"; char[] strCharArr = str.ToCharArray(); //结果 //strCharArr[0]='A', //st ...