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个位置所能搭建的最大高度,问以哪一个位置的塔的高度为基准向左的每一个塔都 ...
随机推荐
- 【Spring】Spring 入门
Spring 入门 文章源码 Spring 概述 Spring Spring 是分层的 Java SE/EE 应用全栈式轻量级开源框架,以 IOC(Inverse Of Control,反转控制)和 ...
- Java开发手册之编程规约
时隔一年多,再次开始更新博客,各位粉丝们久等了.大家是不是以为我像大多数开发者一样三分钟热度,坚持了一年半载就放弃了,其实不是.在过去的一年时间我学习了<Java编程思想>这本书,因为都是 ...
- 【Linux】用yum来下载rpm,而不安装
方法一:yum yum命令本身就可以用来下载一个RPM包,标准的yum命令提供了--downloadonly(只下载)的选项来达到这个目的. $ sudo yum install --download ...
- 【Linux】linux的所有文件分类解析
今天看书的时候,无意间看到/dev/文件夹,以前没注意,今天去看了下发现,很多文件的开头文件属性都是一些不怎么见到的 常见的是 - 这个是代表文件,可以vim编辑的 d 这个是代表 ...
- 【Linux】tcpdump
tcpdump介绍 tcpdump 是一个运行在命令行下的抓包工具.它允许用户拦截和显示发送或收到过网络连接到该计算机的TCP/IP和其他数据包.tcpdump 适用于 大多数的类Unix系统操作系统 ...
- CentOS6.8安装及各种坑
实现目的:用U盘安装CentOS 6.2 32位系统 所需工具: 一.UltraISO(用来制作U盘启动) 下载地址:http://www.newhua.com/soft/614.htm 二.Cent ...
- Springboot之文件监控
背景:在实际环境部署构成中,由于特殊网络环境因素,有很多服务器之间的网络都是单向的,不能互相访问的,只有通过特定技术手段做到文件的单项摆渡,这就需要在两台服务器上分别写序列化程序和反序列化程序,这里不 ...
- Cookie&Session&Jsp总结
知识点梳理 Cookie&Session&Jsp 1 会话技术 1.1 会话管理概述 1.1.1 会话技术介绍 会话:浏览器和服务器之间的多次请求和响应 (一次对话) 为了实现一些功能 ...
- Redis 实战 —— 06. 持久化选项
持久化选项简介 P61 Redis 提供了两种不同的持久化方法来将数据存储到硬盘里面. RDB(redis database):可以将某一时刻的所有数据都写入硬盘里面.(保存的是数据本身) AOF(a ...
- ryu—流量监视
1. 代码解析 ryu/app/simple_monitor_13.py: from operator import attrgetter from ryu.app import simple_swi ...