Codeforces Round #622 (Div. 2) B. Different Rules(数学)
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(数学)的更多相关文章
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
- Codeforces Round #622 (Div. 2) 1313 B Different Rules
B. Different Rules Nikolay has only recently started in competitive programming, but already qualifi ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #622 (Div. 2).C2 - Skyscrapers (hard version)
第二次写题解,请多多指教! http://codeforces.com/contest/1313/problem/C2 题目链接 不同于简单版本的暴力法,这个数据范围扩充到了五十万.所以考虑用单调栈的 ...
- 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 ...
- Codeforces Round #622 (Div. 2)C2 Skyscrapers最大"尖"性矩形,思维||分治
题:https://codeforces.com/contest/1313/problem/C2 题意:给出n个数,分别代表第i个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...
随机推荐
- C# 设置默认关联程序
以下代码做个Mark /// <summary> /// Create an associaten for a file extension in the windows registry ...
- centos7 在虚拟机中装好后的网络连接问题
1.首先设置网卡连接方式:点"设置",在弹出的界面中点"网络",最后选择"连接方式"为"桥接网卡" 2.用Vim编辑器打 ...
- db_install.rsp dbca.rsp netca.rsp 详解【转】
db_install.rsp详解 #################################################################### ## Copyright(c ...
- 【剑指 Offer】07.重建二叉树
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 示例: 前序遍历 preorder = [3,9,20,15,7] 中序遍历 ...
- (数据科学学习手札103)Python+Dash快速web应用开发——页面布局篇
本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 这是我的系列教程Python+Dash快速web ...
- SQL查找连续出现的数字
基于Oracle: 题:编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+ | Id | Num | +----+-----+ | 1 | 1 | | 2 | 1 | ...
- C# ADO.NET连接字符串详解
C#中连接字符串包含以下内容 参数 说明 Provider 设置或者返回提供的连接程式的名称,仅用于OLeDbConnection对象 Connection Timeout 在终止尝试并产生异常前,等 ...
- apijson简单使用
apijson简单使用 介绍 APIJSON 是一种专为 API 而生的 JSON 网络传输协议 以及 基于这套协议实现的 ORM 库.为简单的增删改查.复杂的查询.简单的事务操作 提供了完全自动化的 ...
- Nacos 服务配置中心
1.因为项目是微服务分布式项目,每个微服务都需要用到配置中心,所以第一步我们先在common中添加相应的依赖 <dependency> <groupId>com.alibaba ...
- 十九、更改LCD显示屏
一.裸机修改 之前测试用的屏幕是480*272的分辨率,现在要换成800*480的屏,因此要对软件代码进行修改. 对于裸机驱动而言,主要有两个点需要注意,一个是屏幕分辨率变了,因此初始化的时候与屏幕分 ...