CF Round946 (Div. 3)A
Phone Desktop
题目描述
Little Rosie has a phone with a desktop (or launcher, as it is also called). The desktop can consist of several screens. Each screen is represented as a grid of size $ 5 \times 3 $ , i.e., five rows and three columns.
There are $ x $ applications with an icon size of $ 1 \times 1 $ cells; such an icon occupies only one cell of the screen. There are also $ y $ applications with an icon size of $ 2 \times 2 $ cells; such an icon occupies a square of $ 4 $ cells on the screen. Each cell of each screen can be occupied by no more than one icon.
Rosie wants to place the application icons on the minimum number of screens. Help her find the minimum number of screens needed.
输入格式
The first line of the input contains $ t $ ( $ 1 \leq t \leq 10^4 $ ) — the number of test cases.
The first and only line of each test case contains two integers $ x $ and $ y $ ( $ 0 \leq x, y \leq 99 $ ) — the number of applications with a $ 1 \times 1 $ icon and the number of applications with a $ 2 \times 2 $ icon, respectively.
输出格式
For each test case, output the minimal number of required screens on a separate line.
样例 #1
样例输入 #1
11
1 1
7 2
12 4
0 3
1 0
8 1
0 0
2 0
15 0
8 2
0 9
样例输出 #1
1
1
2
2
1
1
0
1
1
2
5
提示
The solution for the first test case can look as follows:
Blue squares represent empty spaces for icons, green squares represent $ 1 \times 1 $ icons, red squares represent $ 2 \times 2 $ iconsThe solution for the third test case can look as follows:

AC_code
本人丑陋的模拟写法
#include <iostream>
using namespace std;
int _;
int x, y;
int sum ,d;
int main()
{
cin >> _;
while(_ --) {
cin >> x >> y;
sum = 0;
d = y / 2;
sum += 7 * d;
if(y % 2 != 0) sum += 11, d += 1;
if(x <= sum) cout << d << endl;
else {
x -= sum;
int f = 0;
while(x > 0) {
x -= 15, ++ f;
}
cout << d + f << endl;
}
}
return 0;
}
听完题解get到写法
#include <iostream>
using namespace std;
int _;
int x, y, d, sum;
void solve() {
d = (y + 1) / 2;//上取整
if(x > d * 15 - y * 4) {
x -= d * 15 - y * 4;
d += (x + 1) / 15;//上取整
}
cout << d << endl;
}
int main()
{
cin >> _;
while(_ -- ) {
cin >> x >> y;
solve();
}
return 0;
}
get到技能:上取整(分母 - 1)
分母 - 1再除以除数
int x = 310;
cout << (x + 14) / 15;//通常使用比除数更小1的数构造上取整
复习:先将一个数变为正数再取模
正数返回本身,负数变为正数再取模
int x = -6;
cout << (x + 10) % 10 << endl;
贪心:先猜22,再猜11
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int x, y;
std::cin >> x >> y;
int ans = std::max((y + 1) / 2, (x + 4 * y + 14) / 15);
std::cout << ans << "\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while(t --) {
solve();
}
return 0;
}
后记
蒟蒻第一场CF(div3)被按在地上摩擦,只Ac了一题,第二题构造映射被卡,接下来决定加训疯狂补题T.T,第一次交题不注意还交错文件了
码力超弱,写个模拟题都花费大量时间
CF Round946 (Div. 3)A的更多相关文章
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
- CF #371 (Div. 2) C、map标记
1.CF #371 (Div. 2) C. Sonya and Queries map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- CF#138 div 1 A. Bracket Sequence
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...
- CF 552(div 3) E Two Teams 线段树,模拟链表
题目链接:http://codeforces.com/contest/1154/problem/E 题意:两个人轮流取最大值与旁边k个数,问最后这所有的数分别被谁给取走了 分析:看这道题一点思路都没有 ...
- CF 222 (DIV 1)
A: 我是bfs出一颗树,然后删掉树后面的k个结点. 其实也可以直接bfs出一块连通的s - k个点,其余的.打X就可以了. 很水的题目. /* *************************** ...
随机推荐
- 阿里云Ansible自动化运维平台部署
以下是在阿里云平台上基于Ansible实现自动化运维的完整实践指南,整合所有核心操作流程和命令,适配指定的服务器规划: 一.环境规划 主机名 IP地址 角色 操作系统 manage01 192.168 ...
- H5完美适配刘海屏和状态栏高度的全机型解决方案攻略
@charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...
- Windows配置VS Code详细流程
本文介绍Visual Studio Code(VS Code)软件在Windows操作系统电脑中的下载.安装.运行方法. Visual Studio Code(简称VS Code)是一款由微软 ...
- Hystrix 服务的隔离策略对比,信号量与线程池隔离的差异
支持的隔离策略 Hystrix支持的 hytrix支持线程池隔离和信号量隔离 信号量的隔离: it executes on the calling thread and concurrent requ ...
- Serial-Studio 上位机编译全过程深度讲解,解决串口数据可视化工具
Windows环境下编译Serial-Studio Serial-Studio是一个开源的串口数据可视化工具,广泛应用于物联网.嵌入式系统调试和数据分析等领域.从源代码编译Serial-Studio可 ...
- yoga14c2024(ultra7-155H)使用雷电4转接oculink外接RTX4070Ti Super跑分
yoga14c2024(ultra7-155H)使用雷电4转接oculink外接RTX4070Ti Super跑分 自媒体跑分 内屏 \[损耗=1-16731/24723\approx32.3\%\n ...
- CSP-S 2020模拟训练题1-信友队T2 挑战NPC
题意简述 有一个\(k\)维空间,每维的跨度为\(L\),即每一维的坐标只能是\(0,1, \cdots ,L-1\).每一步你可以移动到任意一个曼哈顿距离到自己小于等于\(d\)的任意一个合法坐标. ...
- .NET 9中的异常处理性能提升分析:为什么过去慢,未来快
一.为什么要关注.NET异常处理的性能 随着现代云原生.高并发.分布式场景的大量普及,异常处理(Exception Handling)早已不再只是一个冷僻的代码路径.在高复杂度的微服务.网络服务.异步 ...
- 「ABC 406 G」Travelling Salesman Problem
「ABC 406 G」Travelling Salesman Problem 前言 本题笔者使用了两种方法来做,一是 \(\text{Slope trick}\) ,二是线段树,皆有讲解,各位读者按需 ...
- 深入浅出容器学习--Docker网络
一.Docker的网络概念 容器网络模型主要包含了三个概念: network:网络,这里可以理解为一个Driver,是一个第三方网络栈,包含多种网络模式. 单主机网络模式(none.host.brid ...