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就可以了. 很水的题目. /* *************************** ...
随机推荐
- Rolldown:下一代JavaScript/TypeScript打包工具,基于Rust的JS打包工具-速度贼快
Vue 团队已正式开源 Rolldown 项目,这是一款基于 Rust 的 JavaScript 打包工具. 项目介绍 Rolldown 是使用 Rust 开发的 Rollup.js 编译工具的替代品 ...
- DP 动态规划初识
前面的 HMM 中参数求解, 都会用到动态规划, 全是各种概率公式, 是有一些抽象, 今天决定举个一波简单的栗子, 帮助理解DP 把一个大问题,不断划分为更小的子问题来求解的这种方式, 就是动态规划. ...
- Git-如何区分使用个人账户和公司账户
个人日常编写点小玩具,code 的版本控制一般托管于GitHub,但是公司内部使用 GitLb 来进行代码版本控制,这样为了能够在同一台 MacBook(自带,公司有补贴)日常区分出两个账户,通过翻阅 ...
- 【中文】【吴恩达课后编程作业】Course 4 - 卷积神经网络 - 第三周作业
[中文][吴恩达课后编程作业]Course 4 - 卷积神经网络 - 第三周作业 - 车辆识别 上一篇:[课程4 - 第三周测验]※※※※※ [回到目录]※※※※※下一篇:[课程4 - 第四周测验] ...
- CommonsBeanutils链与无commons collections的shiro反序列化利用
CommonsBeanutils链与无commons collections的shiro反序列化利用 在cc2中,我们知道可以在commons-collections4通过java.util.Comp ...
- Vite代理配置不生效问题
1.问题: 在写Vite+vue3.0项目时,配置vite代理,遇到不起效的问题,具体如下: // vite.config.ts proxy: { '/api': ' http://localhost ...
- 优化PHP开发流程:精选工具与配置指南,提升代码质量与效率
本文由 ChatMoney团队出品 在PHP开发领域,选择正确的工具可以极大地提升开发效率和代码质量. 集成开发环境(IDE) PHPStorm 是一个强大的IDE,专为PHP开发设计.它提供了丰富的 ...
- TensorBoard使用报错
TensorBoard使用报错 1.报错如下 Traceback (most recent call last): File "E:\AI_DP\xtd\3-Tensorboard用途.py ...
- 一、Linux常用命令(ubuntu/debian)
1.rename(批量修改文件名) rename 's/屏幕录制 2024-09-06 123248_/aa_/' 屏幕录制\ 2024-09-06\ 123248_*.png 这条命令的含义是: s ...
- linux0.01代码阅读
代码地址: https://cdn.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz 代码目录: main函数: 代码中的命名解释: CMO ...