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. 使用Java语言编写一个五子棋UI界面并实现网络对战功能(非局域网)

    使用Java语言编写一个五子棋UI界面并实现网络对战功能(非局域网) 一,前期准备 1,Java IDE(Eclipse)与JDK的安装与配置jdk-15.0.1-免配置路径版提取码:earu免安装版 ...

  2. swoole中websoket创建在线聊天室(php)

    swoole中websoket创建在线聊天室(php) swoole现仅支持Linix,macos 创建websocket服务器 首先现在服务器创建一个websocket服务器 <?php // ...

  3. 【MyBatis】自定义 MyBatis

    自定义 MyBatis 文章源码 执行查询信息的分析 我们知道,MyBatis 在使用代理 DAO 的方式实现增删改查时只做两件事: 创建代理对象 在代理对象中调用 selectList() 配置信息 ...

  4. 初识JWT

    1.JWT是什么 官方网站 JWT是JSON Web Token的简称.是一种开放标准(RFC 7519),定义了一种紧凑且自包含的方式,以JSON对象的形式在各方之间安全地传输信息,因为他被数字签名 ...

  5. 【MySQL】DDL数据定义语言的基本用法create、drop和alter(增删改)

    DDL 的基础语法 文章目录 DDL 的基础语法 对数据库进行定义 对数据表进行定义 创建表结构(数据表) 设计工具 修改表结构 小结 参考资料 简单复习一波 SQL必知必会 DDL 的英文全称是 D ...

  6. 【Spring】Spring的数据库开发 - 1、Spring JDBC的配置和Spring JdbcTemplate的解析

    Spring JDBC 文章目录 Spring JDBC Spring JdbcTemplate的解析 Spring JDBC的配置 简单记录-Java EE企业级应用开发教程(Spring+Spri ...

  7. RandomForest 随机森林算法与模型参数的调优

    公号:码农充电站pro 主页:https://codeshellme.github.io 本篇文章来介绍随机森林(RandomForest)算法. 1,集成算法之 bagging 算法 在前边的文章& ...

  8. 如何跑通第一个 SQL 作业

    简介: 本文由阿里巴巴技术专家周凯波(宝牛)分享,主要介绍如何跑通第一个SQL. 一.SQL的基本概念 1.SQL 分类 SQL分为四类,分别是数据查询语言(DQL).数据操纵语言(DML).数据定义 ...

  9. 【Oracle】更改oracle中的用户名称

    修改oracle中的用户名,要需要修改oracle基表中的相关内容, 1.查看user#, select user#,name from user$ s where s.name='用户修改前的'; ...

  10. DataGridView控件使用Demo

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...