题解 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. Tomcat Lifecycle

    org.apache.catalina.Lifecycle 接口统一管理生命周期,所有生命周期组件都要实现Lifecycle接口. 该接口定义了13个String类型的常量,用于LifecycleEv ...

  2. 关于 false sharing

    问题来源 在多线程操作中,每个线程对操作对象都会有单独的缓存,最后将缓存同步到内存上,不加锁的话会导致数据缺乏同步出现错误,如果只是简单地加锁,性能就会飞速下降 解法 spacing &&am ...

  3. .NetCore/ .NetFramework 机制

    1.每来一个请求,会启动一个线程. 可以通过下面代码打印出来. 这个线程是主线程,如果用异步,会等待异步线程执行完毕才会返回. 这有个现象,用stmp 发邮件的时候,即使用异步,也会比较卡(选用的邮件 ...

  4. 一、openfeign的自动配置

    所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 openfeign是一种声明式的webservice客户端调用框架.你只需要声明接口和一 ...

  5. 基于【 bug解决】一 || mysql的ONLY_FULL_GROUP_BY导致的sql语句错误

    一.Mysql错误: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated ...

  6. win10如何安装mariadb

    一.下载.安装 1.下载mariadb(https://downloads.mariadb.org/),解压 2.进入bin目录下执行(管理员模型-powershell) .\mysqld.exe - ...

  7. 50个Sql语句实战

    /* 说明:以下五十个语句都按照测试数据进行过测试,最好每次只单独运行一个语句. 问题及描述:--1.学生表Student(S#,Sname,Sage,Ssex) --S# 学生编号,Sname 学生 ...

  8. java数据类型转换的常见方法

    public class Testfun { public static void main(String[] args) { // (一)跨Number父类的类型转换 // 1.str转int =& ...

  9. 【坑】select2 模态框中下拉input无法focus

    select2的组件bug 解决方案: 在bootstrap.js中修改: Modal.prototype.enforceFocus = function () { $(document) .off( ...

  10. http接口测试工具-Advanced-REST-client

    非常好用的http接口测试工具 相信作为一个java开发人员,大家或多或少的要写或者接触一些http接口.而当我们需要本地调试接口常常会因为没有一款好用的工具而烦恼.今天要给大家介绍一款非常好用.实用 ...