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

这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵。

第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分。幸亏这次没有掉rating。

比赛传送门:https://codeforces.com/contest/1080

A.Petya and Origami

题意:Petya要发出n张邀请函,每张请函需要2张红纸,5张绿纸,8张蓝纸。现在商店里有一些不同颜色的笔记本,每本中有k张颜色相同的纸,求最少要买几本笔记本。

这题就是一道模拟题,算出每种纸的数量,答案加上数量除以k,对于每张颜色如果还有余数,答案加一。

代码如下:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x,y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = ;
int lowbit(int x){ return x & -x; }
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p; } return x; }
//head by DYH int main(){
int n, k;
scanf("%d%d", &n, &k);
int a = n * , b = n * , c = n * ;
int ans = a / k + b / k + c / k;
if(a % k) ans++;
if(b % k) ans++;
if(c % k) ans++;
printf("%d\n", ans);
return ;
}

Problem-A

B. Margarite and the best present

题意:有一个序列,ai = (-1)i * i,现在有t个询问,问你ax~y的和。

看到这题想到了小学奥数题,对于每个询问只要求a1~y - a1~x-1就好了,至于a1~i就很好求了,当i是偶数就是i / 2, 否则是i - i / 2。搞不懂为什么有人在luogu群上问这题是不是莫队(蒟蒻表示压根不会莫队)。

代码如下:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x,y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int INF = << ;
const int p = ;
int lowbit(int x){ return x & -x; }
int fast_power(int a, int b){ int x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p; } return x; }
//head by DYH int solve(int x){
int res = x / ;
if(x % == ) res -= x;
return res;
} int main(){
int t;
scanf("%d", &t);
rep(times, , t){
int x, y;
scanf("%d%d", &x, &y);
int ans = solve(y) - solve(x - );
printf("%d\n", ans);
}
return ;
}

Problem-B

C.Masha and two friends

题意:有一个n * m的黑白相间的棋盘,(1, 1)为白色。现在把(x1, y1)到(x2, y2)这个矩阵涂白(x1 <= x2, y1 <= y2),再把(x3, y3)到(x4, y4)这个矩阵涂黑(x3 <= x4, y3 <= y4)。现在问你有多少个黑格子和白格子。注:有多组数据。

A 、B两题都挺水,C、D开始就是数学题了,感觉自己好菜。

要求求黑格子和白格子,只要求其中一个就好了,另一个就是拿总个数减一下,我就是求白格子的个数。

这题看上去很烦(其实打起来也很烦),但其实就是原有的个数 + 第一次涂白的黑格子个数 - 第二次涂黑的白格子个数。

第一次涂白的黑格子数就是(x1, y1)到(x2,y2)这个矩阵中原有的黑格数(然而我统计了白格子个数再拿总数减)。

统计白格子的个数方法就是总的格子个数 / 2, 如果总个数是奇数,就看左下角是否是白格子((x + y) % 2 == 0)。求黑格子数也是一样。

求第二次涂黑的白格子个数是(x3, y3)到(x4, y4)这个矩阵原有的白格数 + 两次涂色相交的矩阵中原来黑格子的个数(因这些格子已经被涂成白色,已经被算入答案,要减掉)。

求区间内原有的黑白格数我就不再说了,主要就是求相交的矩阵。

先判断有无相交:

x2 < x3 || x1 > x4 || y2 < y3 || y1 > y4  

可以画个图方便理解。

然后就是相交的矩阵的坐标。(用X1, Y1, X2, Y2表示)

X1 = max(x1, x3), X2 = min(x2, x4), Y1 = max(y1, y3), Y2 = min(y2, y4)

  

这题就这样草率的讲完了,有不理解可以看代码画几个图模拟下。

代码如下

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define rep(x, l, r) for(LL x = l; x <= r; x++)
#define repd(x, r, l) for(LL x = r; x >= l; x--)
#define clr(x,y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define MAXN
#define fi first
#define se second
#define SZ(x) ((LL)x.size())
using namespace std;
typedef long long LL;
typedef vector<LL> vi;
typedef pair<LL, LL> pii;
const LL INF = << ;
const LL p = ;
LL lowbit(LL x){ return x & -x; }
LL fast_power(LL a, LL b){ LL x; for(x = ; b; b >>= ){ if(b & ) x = 1ll * x * a % p; a = 1ll * a * a % p; } return x; }
//head by DYH LL judge(LL x1, LL y1, LL x2, LL y2){
LL x = x2 - x1 + , y = y2 - y1 + ;
LL res = x * y / ;
if(x * y % == && (x1 + y1) % == ) res++;
return res;
} LL check(LL x1, LL y1, LL x2, LL y2, LL x3, LL y3, LL x4, LL y4){
if(x2 < x3 || x1 > x4 || y2 < y3 || y1 > y4) return ;
LL X1 = max(x1, x3), X2 = min(x2, x4), Y1 = max(y1, y3), Y2 = min(y2, y4);
return (X2 - X1 + ) * (Y2 - Y1 + ) - judge(X1, Y1, X2, Y2);
} int main(){
LL t;
scanf("%I64d", &t);
rep(times, , t){
LL n, m;
scanf("%I64d%I64d", &n, &m);
LL x1, y1, x2, y2, x3, y3, x4, y4;
scanf("%lI64d%I64d%Id%I64d%I64d%I64d%I64d%I64d", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
LL ans = judge(, , n, m);
ans += (x2 - x1 + ) * (y2 - y1 + ) - judge(x1, y1, x2, y2);
ans -= check(x1, y1, x2, y2, x3, y3, x4, y4) + judge(x3, y3, x4, y4);
printf("%I64d %I64d\n", ans, n * m - ans);
}
return ;
}

Problem-C

完成日期:2018-11-25 04:05:27

Codeforces Round #524 (Div. 2)(前三题题解)的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  4. Codeforces Round #460 (Div. 2) 前三题

    Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #in ...

  5. Codeforces Round #599 (Div. 2)的简单题题解

    难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...

  6. Codeforces Round #530 (Div. 2) (前三题题解)

    总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...

  7. Codeforces Round #195 A B C 三题合集 (Div. 2)

    A 题 Vasily the Bear and Triangle 题目大意 一个等腰直角三角形 ABC,角 ACB 是直角,AC=BC,点 C 在原点,让确定 A 和 B 的坐标,使得三角形包含一个矩 ...

  8. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  9. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

随机推荐

  1. @雅礼集训01/06 - T3@ math

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给出 n, m, x,你需要求出下列式子的值: \[\sum_{ ...

  2. 高二小假期集训—D5

    刚调完了一个非常恶心的题(可能是我写的太恶心了),心累……先写会博客吧. 今天上午该完了考试的三道题,感觉第二道真的是个好题(学长说是经常会遇到的一类题……完了完了),看了一个小时std才看懂,写了篇 ...

  3. Getting started with the basics of programming exercises_1

    1.编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替 使用if 结构: #include<stdio.h> #define NONBLANK 'a'; // repal ...

  4. hdu 3662 3D Convex Hull

    Problem - 3662 题意很简单,构造三维凸包,求凸包有多少个面. 代码如下: #include <cstdio> #include <iostream> #inclu ...

  5. 为 Ubuntu 18.04 添加开机自动加载 ntfs分区 功能

    注意:Ubuntu终端命令是区分大小写的 1,准备的:     ntfs-3g -- 提供ntfs读写支持(一般说来是自带的,若没有,可是使用 sudo apt-get isntall ntfs-3g ...

  6. poj 1920 Towers of Hanoi

    Towers of Hanoi Time Limit: 3000MS   Memory Limit: 16000K Total Submissions: 2213   Accepted: 986 Ca ...

  7. 常用的python内建函数

    raw_input() 函数说明 函数签名:raw_input([prompt]) 使用形式如下: raw_input([prompt]) -> string 如果提供了参数prompt,就会在 ...

  8. PPP验证对比

  9. P1103 走迷宫三

    题目描述 大魔王抓住了爱丽丝,将她丢进了一口枯井中,并堵住了井口. 爱丽丝在井底发现了一张地图,他发现他现在身处一个迷宫当中,从地图中可以发现,迷宫是一个N*M的矩形,爱丽丝身处迷宫的左上角,唯一的出 ...

  10. H3C IPv6地址分类