题解 CF1080A 【Petya and Origami】

这道题其实要我们求的就是

\[\lceil 2*n/k \rceil + \lceil 5*n/k \rceil + \lceil 8*n/k \rceil
\]

然后就做完了

# 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)题解的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. vue防止闪屏小技巧:[v-cloak]

    css 内添加此属性[v-cloak] { display: none; } html中引入即可 <div v-cloak> {{ message }} </div> 如果觉得 ...

  2. SQL Server的非聚集索引中会存储NULL吗?

    原文:SQL Server的非聚集索引中会存储NULL吗? SQL Server的非聚集索引中会存储NULL吗? 这是个很有意思的问题,下面通过如下的代码,来说明,到底会不会存储NULL. --1.建 ...

  3. JavaDoc工具和Ideade javadoc工具

    命令参考: javadoc -locale zh_CN -protected -notree -nonavbar -noindex -use -author -version -encoding UT ...

  4. 【转载】 C#中使用Sum方法对List集合进行求和操作

    在C#的List操作中,有时候我们需要对List集合对象的某个属性进行求和操作,此时可以使用Lambda表达式中的Sum方法来快速实现此求和操作,使用Sum方法可使代码简洁易读,并且省去写for循环或 ...

  5. 11/8 (tell tales web)

    1.visual perception gestalt theory:格式塔学派是心理学重要流派之一,兴起于20世纪初的德国,又称为完形心理学.由马科斯·韦特墨.沃尔夫冈·苛勒和科特·考夫卡三位德国心 ...

  6. Thinkphp中的assign() 和 display()

    说到 $this->assign()  与 $this->display()想必用过TP框架的都不陌生,那么今天我们就来说说他们的作用及其他用法. 先说 $this->assign( ...

  7. S5PV210 启动流程

    S3C6410启动流程 首先,看一下S3C6410启动流程 ① iROM supports initial boot up : initialize system clock, D-TCM, devi ...

  8. MySQL常见问题集锦及注意事项

    一.表设计上的坑 1.字段设计 1.1 字段类型设计 尽量使用整型表示字符串: `INET_ATON(str)`,address to number `INET_NTOA(number)`,numbe ...

  9. 3-JavaSe-1-stream-1-流库特征

    1.parallelStream可以让流库以并行方式来执行过滤和计数. String content=new String(Files.readAllBytes(Paths.get("D:\ ...

  10. 【DELL存储】EMC会议 超融合+存储

    场景:盐城工厂 IT人数 4个人  机房200台 主要以虚拟化为主 实体机 PG ORACAL MYSQL dell产品线 提供整体方案 架构 针对整车厂 :传统+超融合 1. 介绍产品 1.1 超融 ...