Codeforces Round #622 (Div. 2) B. Different Rules

题意:

你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n 和你两场分赛的排名 x, y,问你最终名次最小和最大可能是多少。

思路:

以8人为例:

x + y = 2,最小第一名,最大第一名:

              1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1              

x + y = 3,最小第一名,最大第二名。

            1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1            

x + y = n + 1,最小第二名,最大第 n 名。

1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1

x + y = n + 2,最小第三名,最大第 n 名。

1 2 3 4 5 6 7 8  
  8 7 6 5 4 3 2 1

没错,相信聪明的你已经发现规律了:

  • 当 2 ≤ x + y  ≤ n 时,最小值总为第一名,最大值取决于 x + y 比 2 大多少,每大 1 就会对齐一对和为 x + y 的数,即最大名次 + 1。
  • 当 n + 1 ≤ x + y ≤ 2n 时,最大值总为第 n 名,最小值取决于 x + y 比 n + 1 大多少,每大 1 就会错出一对和小于 x + y 的数,即最小名次 + 1。
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,x,y;cin>>n>>x>>y;
if(x+y<=n) cout<<1<<' '<<x+y-1<<endl;
else cout<<min(n,x+y-n+1)<<' '<<n<<endl;
}
int main()
{
int t;cin>>t;
while(t--)
solve();
return 0;
}

Codeforces Round #622 (Div. 2) B. Different Rules(数学)的更多相关文章

  1. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)

    Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...

  2. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)

    Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...

  3. Codeforces Round #622 (Div. 2) 1313 B Different Rules

    B. Different Rules Nikolay has only recently started in competitive programming, but already qualifi ...

  4. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  5. Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)

    第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...

  8. Codeforces Round #622 (Div. 2) A. Fast Food Restaurant

    Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made ...

  9. Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治

    题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...

随机推荐

  1. ElasticSearch- 单节点 unassigned_shards 故障排查

    故障现象 在部署ELK的单机环境,当连接Kibana时候提示下面错误,即使重启整个服务也是提示Kibana server is not ready. {"message":&quo ...

  2. 在CentOS上安装Singularity高性能容器

    什么是singularity容器 Singularity是劳伦斯伯克利国家实验室专门为大规模.跨节点HPC和DL工作负载而开发的容器化技术.具备轻量级.快速部署.方便迁移等诸多优势,且支持从Docke ...

  3. 使用Jenkins+Blue Ocean 持构建自动化部署之安卓源码打包、测试、邮件通知

    什么是BlueOcean? BlueOcean重新考虑了Jenkins的用户体验.BlueOcean由Jenkins Pipeline设计,但仍然兼容自由式工作,减少了团队成员的混乱,增加了清晰度. ...

  4. vmstat参数详解

    vmstat 5 可以使用ctrl+c停止vmstat,可以看到输出依赖于所用的操作系统,因此可能需要阅读一下手册来解读报告 第一行的值是显示子系统启动以来的平均值,第二行开始展示现在正在发生的情况, ...

  5. SVM 支持向量机算法-实战篇

    公号:码农充电站pro 主页:https://codeshellme.github.io 上一篇介绍了 SVM 的原理和一些基本概念,本篇来介绍如何用 SVM 处理实际问题. 1,SVM 的实现 SV ...

  6. Java并发包源码学习系列:JDK1.8的ConcurrentHashMap源码解析

    目录 为什么要使用ConcurrentHashMap? ConcurrentHashMap的结构特点 Java8之前 Java8之后 基本常量 重要成员变量 构造方法 tableSizeFor put ...

  7. 微信登录2-生成授权URL

    一.准备工作 1.注册 微信开放平台:https://open.weixin.qq.com 2.邮箱激活 3.完善开发者资料 4.开发者资质认证 准备营业执照,1-2个工作日审批.300元 5.创建网 ...

  8. 关于MongoDB的简单理解(一)--基础篇

    一.什么是MongoDB? MongoDB是一个基于分布式文件存储的文档数据库,旨在简化开发和扩展,为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之 ...

  9. SELECT ... FOR UPDATE or SELECT ... FOR SHARE Locking Reads session

    小结: 1.注意使用限制 Locking reads are only possible when autocommit is disabled (either by beginning transa ...

  10. https://github.com/golang/go/wiki/CommonMistakes

    CommonMistakes https://golang.org/doc/faq#closures_and_goroutines Why is there no goroutine ID? ¶ Go ...