【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节介绍了字符流,它们都是以流的方式读写文件,流的方式有几个限制: 要么读,要么写,不能同时读和写 不能随机读写,只能从头读到尾,且不能重复读,虽然通过缓冲可以实现部分重读,但 ...
随机推荐
- Oracle 数据库优化
Oracle 数据库优化 参考网址
- python web自动化测试框架搭建(功能&接口)——功能测试模块
功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...
- 【Unity 系统知识】 各种路径
一.Assets下的Resources(Unity系统文件夹) :路径 Application.dataPath/Resources 可以使用Resources.Load("文件名字,注:不 ...
- [LeetCode] 477. Total Hamming Distance(位操作)
传送门 Description The Hamming distance between two integers is the number of positions at which the co ...
- C#的一般处理程序中Cookie的写入、读取、清除
1.写入Cookie值 string userName = context.Request.Form["u_Name"].ToString().Trim(); string pwd ...
- Java8 Nashorn JavaScript引擎
使用Java8,Nashorn大大提高了JavaScript 引擎引入,以取代现有的Nashorn Java脚本引擎.Nashorn提供2至10倍更好的性能,因为它直接编译代码在存储器,并传递到字节码 ...
- iintellij IDEA运行环境使用教程
1.官网:https://www.jetbrains.com 链接: https://pan.baidu.com/s/10QKLn1bGEW9W0pXEp6WR1A 提取码: vt2b 看官觉得有用留 ...
- java序列化的相关介绍
1.什么是序列化?为什么要用序列化? 序列化就是将对象状态转换为可保持或传输的格式的过程.与序列化相对的就是反序列化,他将流转换成对象.这两个过程结合起来,可以轻松地存储和传输数据. 注意:对象序列化 ...
- 用bootstrap和css3制作按钮式下拉菜单
利用bootstrap框架的字体图标和下拉菜单效果,以及css3的动画效果,可以做出比较优雅的按钮式下拉菜单样式 <style> .myBtnStyle .dropdown-menu sp ...
- [fw]Nvidia Linux Drive Privilege Escalation
/* Anonymous * * How to use: sudo rm -rf / * * greetz: djrbliss, kad, Ac1dB1tch3z, nVidia! * * Only ...