Codeforces Round #524 (Div.2)题解
题解 CF1080A 【Petya and Origami】
这道题其实要我们求的就是
\]
然后就做完了
# include <bits/stdc++.h>
# define ll long long
int main()
{
ll n, k;
scanf("%lld%lld", &n, &k);
ll ans = ((2 * n) / k) + ((5 * n) / k) + ((8 * n) / k) + bool((2 * n) % k != 0) + bool((5 * n) % k != 0) + bool((8 * n) % k != 0);
printf("%lld\n", ans);
return 0;
}
题解 CF1080B 【Margarite and the best present】
这道题其实求的是区间内偶数和减去奇数和
用等差数列求和公式即可
注意区间长度要\(+1\)
# include <bits/stdc++.h>
# define ll long long
int main()
{
int q;
scanf("%d", &q);
while(q--)
{
ll l, r;
ll ans;
scanf("%I64d%I64d", &l, &r);
if(l == r)
{
printf("%I64d\n", ((l % 2) ? -l : l));
continue;
}
ll x, y;
ll lodd = ((l % 2 == 1) ? l : l + 1), leven = ((l % 2 == 0) ? l : l + 1), rodd = ((r % 2 == 1) ? r : r - 1), reven = ((r % 2 == 0) ? r : r - 1);
x = ((reven - leven) / 2 + 1) * ((reven + leven) / 2);
y = ((rodd - lodd) / 2 + 1) * ((rodd + lodd) / 2);
//printf("%d %d %d %d\n", leven, lodd, reven, rodd);
ans = x - y;
printf("%I64d\n", ans);
}
return 0;
}
题解 CF1080C 【Masha and two friends】
这道题要注意的细节超级多,是一道分类讨论好题
其实这道题要求的就是
白色:原白色面积\(+\)矩形\((x1, y1, x2, y2)\)中的黑色面积-矩形\((x3, y3, x4, y4)\)中白色面积-矩形\((x1, y1, x2, y2)\)与矩形\((x3, y3, x4, y4)\)交集中的白色面积(注:本处的黑/白色面积指原矩形中的黑/白面积)
黑色:总面积-白色
好了做完了
(注意:左下角为黑色的矩形中白色的个数为\(\lfloor \frac{n*m}2 \rfloor\),左下角为白色的矩形中白色的个数为\(\lceil \frac{n*m}2 \rceil\))
Code:
#include <bits/stdc++.h>
#define ll long long
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
ll n, m;
ll x[10], y[10];
scanf("%I64d%I64d", &n, &m);
for (int i = 1; i <= 4; i++)
scanf("%I64d%I64d", &x[i], &y[i]), std::swap(x[i], y[i]);
ll w = (n * m + 1) / 2, b = (n * m) - w;
ll c1 = (x[2] - x[1] + 1) * (y[2] - y[1] + 1) - (((x[2] - x[1] + 1) * (y[2] - y[1] + 1) + ((x[1] % 2) == (y[1] % 2))) / 2);
w += c1, b -= c1;
ll c2 = (((x[4] - x[3] + 1) * (y[4] - y[3] + 1) + ((x[3] % 2) == (y[3] % 2))) / 2);
w -= c2, b += c2;
ll c3 = 0;
if (((std::min(x[2], x[4]) >= std::max(x[1], x[3])) && ((std::min(y[2], y[4]) >= std::max(y[1], y[3])))))
c3 = ((std::min(x[2], x[4]) - std::max(x[1], x[3]) + 1) * (std::min(y[2], y[4]) - std::max(y[1], y[3]) + 1)) - ((((std::min(x[2], x[4]) - std::max(x[1], x[3]) + 1) * (std::min(y[2], y[4]) - std::max(y[1], y[3]) + 1))) + ((std::max(x[1], x[3]) % 2) == (std::max(y[1], y[3]) % 2))) / 2;
c3 = std::max(c3, 0ll);
w -= c3, b += c3;
printf("%I64d %I64d\n", w, b);
}
return 0;
}
Codeforces Round #524 (Div.2)题解的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
随机推荐
- 十分钟快速创建 Spring Cloud 项目
一般来说,Intelij IDEA 可以通过 Maven Archetype 来快速生成Maven项目,其实 IDEA 集成了 Spring 官方提供的 Spring Initializr,可以非常方 ...
- CentOS7安装firewall防火墙
CentOS7之后 , 系统已经推荐了firewall防火墙 , 而不是iptables 主要 : firewall 和 iptables冲突 , 需要禁用其中一个. #停止iptables服务 sy ...
- Nginx 配置反向代理ip
参考文档: https://blog.csdn.net/stevenprime/article/details/7918094
- 微信小程序通讯录字母排序
微信小程序通讯录 字母排序效果: demo地址:https://github.com/PeachCoder/wechat-contacts
- Linux:定时任务crond服务
一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cro ...
- Java 之 Properties类 属性集
一.概述 java.util.Properties集合 extends Hashtable<k,v> implements Map<k,v> java.util.Propert ...
- 解决mysql登录警告问题
一.前言 我们在登录mysql的时候经常会看到一句警告: Warning: Using a password on the command line interface can be insecure ...
- python selectors模块实现 IO多路复用机制的上传下载
import selectorsimport socketimport os,time BASE_DIR = os.path.dirname(os.path.abspath(__file__))''' ...
- 软件自带依赖库还是共享对象库/为什么linux发行版之间不能有一个统一的二进制软件包标准
接前文:Linux软件包(源码包和二进制包)及其区别和特点 在前文,我们知道了linux软件包分为源码包和二进制包两种方式,而不同的发行版之间又有着自己的二进制打包格式. 首先,软件运行依赖着各种各样 ...
- linux下的缓存机制buffer、cache、swap - 运维总结 ["Cannot allocate memory"问题]
一.缓存机制介绍 在Linux系统中,为了提高文件系统性能,内核利用一部分物理内存分配出缓冲区,用于缓存系统操作和数据文件,当内核收到读写的请求时,内核先去缓存区找是否有请求的数据,有就直接返回,如果 ...