Atcoder Regular Contest 089D Checker

codeforces1459 B. Move and Turn time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal dire. 阅读详情

Atcoder Regular Contest 089D Checker


Problem Statement

AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3:

cba927b2484fad94fb5ff7473e9aadef.png

AtCoDeer has N desires. The i-th desire is represented by xi, yi and ci. If ci is B, it means that he wants to paint the square (xi,yi) black; if ci is W, he wants to paint the square (xi,yi) white. At most how many desires can he satisfy at the same time?

Constraints
  • 1 ≤ N ≤ 105
  • 1 ≤ K ≤ 1000
  • 0 ≤ xi ≤ 109
  • 0 ≤ yi ≤ 109
  • If i ≠ j, then (xi,yi) ≠ (xj,yj).
  • ci is B or W.
  • N, K, xi and yi are integers.
Input

Input is given from Standard Input in the following format:

N K
x1 y1 c1
x2 y2 c2
:
xN yN cN
Output

Print the maximum number of desires that can be satisfied at the same time.

Sample Input 1
4 3
0 1 W
1 2 W
5 3 B
5 4 B
Sample Output 1
4

He can satisfy all his desires by painting as shown in the example above.

Sample Input 2
2 1000
0 0 B
0 1 W
Sample Output 2
2
Sample Input 3
6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W
Sample Output 3
4

每个点,其实就对应着其横纵坐标%(2*k)的点
然后横(纵)(注意是或,不是且,都+k等于没有反色)坐标+k可以反色
这样,我们就可以得到一个(2*k)*(2*k)的矩形,而且它们都要求同色
然后求二维前缀和(容斥定理)
然后O(k^2)枚举矩形
如图,划分为五个区域,另外四个区域直接n-即可
当然,求矩形内有几个点一样的容斥定理

这里写图片描述

上图整个2k*2k的矩形中所存的点都是一种颜色,所以为了要满足题意,我们只能选择图中黑色或者白色为一种颜色

所以每次枚举计算的个数sum=max(n-sum,sum);

然后枚举矩形图中黑色矩形的位置其实只需要枚举中间黑色小矩形的左上角坐标,其他的通过二维前缀和就都可以表示出来了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int K = 3005;
int x[K][K];
int n,k;
int getsize(int x1,int y1,int x2,int y2){
    return x[x2][y2]-x[x2][y1]-x[x1][y2]+x[x1][y1];
}
int main(){
    scanf("%d%d",&n,&k);
    int a,b,i,j;
    char c;
    for(i = 1; i <= n; i++){
        scanf("%d%d %c",&a,&b,&c);
        a %= (2*k);
        b %= (2*k);
        if(c == 'W')
            b += k;
        x[a%(2*k)+1][b%(2*k)+1]++;
    }
    for(i = 1; i <= 2*k; i++){
        for(j = 1; j <= 2*k; j++){
            x[i][j] = x[i][j]+x[i-1][j]+x[i][j-1]-x[i-1][j-1];
        }
    }
    int ans = 0,sum;
    for(i = 1; i <= k; i++){
        for(j = 1; j <= k; j++){
            sum = getsize(0,0,i,j);
            sum += getsize(i,j,k+i,k+j);
            sum += getsize(k+i,k+j,2*k,2*k);
            sum += getsize(k+i,0,2*k,j);
            sum += getsize(0,k+j,i,2*k);
            sum = max(n-sum,sum);
            ans = max(ans,sum);
        }
    }
    printf("%d\n",ans);
    return 0;
}


防反接电路、防倒灌电路、过流保护和ESP相关知识 1.开关电源给负载供电, 如果负载是电池或者其他感性负载(比如像 电机 有线圈 当电源突然断掉时 会产生感应电动势)时, 当220V断掉的时候,可能会出现 电池反向给开关电源 的 输出端 供电,导致开关电源的一些莫名损坏。2.系统在不同的 输出电压 之间 切换时,会存在高压电压倒灌到低压电压源中。例如:系统 有两个电源供电 比如 一个电池 一个 充电器 充电器的电压一般会高于电池 如果没有防倒灌的电路 可能充电器的电压会直接倒灌给电池 造成电池的损坏。 阅读详情

相关推荐

【学习体会】Lighttools8.4.0:软件基本使用+光度学基本概念+系统初始设置

关于Lighttools8.4.0软件的安装教程,详见我的另一篇博文:【软件安装】win10下Lighttools8.4.0(64)光学系统建模软件的安装教程 在本文中,我们将学习到,光度学的基本概念、系统初始设置、物体模型坐标的使用方法、简单光学系统实例、系统浏览器的作用和内容、设置虚拟相机并渲染视图中的图像、仿真结果3D显示等。 如果有其他感兴趣的内容但是我又没有写的,欢迎在评论区留言! 光度学的基本概念 软件的基本介绍 参考博文:https://www.docin.c...

LeonJin的博客 2万+

保姆级教程:在K230开发板上为张大头步进电机实现位置、速度、回零全功能控制

本文提供了一份详细的K230开发板与张大头步进电机的控制教程,涵盖硬件连接、协议解析、模块化代码实现及实战案例。通过位置、速度和回零功能的全面讲解,帮助开发者快速掌握步进电机的高级控制技术,适用于自动化、机器人等应用场景。

weixin_42629671的博客 708

AtCoder Regular Contest 089

比赛链接 C - Traveling 题意: 有一个平面,初始时在(0,0)点。每次可以花一个时间走到上下左右四个方向。 现在给n个询问,每次询问t,x,y,表示在t时刻是否能到达(x,y)这个坐标。可以输出Yes,否则输出No。 做法: 发现只有两种情况是No: 来不及了,时间小于距离。 距离与时间的差值是奇数。 代码: #include #includ

juruo? juruo! 401

小样本物体检测

Few-Shot Object Detection with Attention-RPN and Multi-Relation Detector 关键:提出了一个小样本数据集:数据集 步骤: 提取support img为一过滤特征 使用support img的特征来过滤query img,最后将过滤后的特征输入RPN网络中 RPN网络层的输出,会进行多头判断,使用全局信息检测,使用局部信息检测,一对多检测 Attention-Based Region Proposal Network Increme

qq_21157073的博客 5266

IC版图设计之OASIS文件格式详解

OASIS(Open Artwork System Interchange Standard)是继GDSII之后新一代的集成电路版图数据交换标准,由SEMI在2004年正式发布(SEMI标准号:SEMI P39)。高压缩率:相比GDSII可减少3-10倍文件体积扩展性强:支持纳米级工艺的复杂图形描述跨平台兼容:独立于EDA工具和操作系统安全增强:内置校验和与加密支持。

ZZcppc的博客 2437

AtCoder086--Checker(黑白格子)

Problem Statement AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black o

岂曰无衣,与子同袍 777

✨在Windows11上安装虚拟机(VMware17.6.0)保姆级教程(附安装包)

VMware Workstation Pro 是一款功能强大的虚拟机软件,它允许你在单一的物理机上运行多个操作系统。性能卓越:VMware以其出色的性能和稳定性而闻名,适合运行资源密集型的虚拟机。用户友好:直观的用户界面使得即使是初学者也能快速上手。功能全面:支持多种操作系统,包括Windows、Linux、macOS等,满足不同用户的需求。企业级支持:VMware提供全面的技术支持,适合企业级用户。恭喜你成功安装了VMware Workstation Pro 17.6.0!

Python老吕的博客 1万+

B. Move and Turn(数论 思维

添加链接描述 如果是偶数,可以上下和左右分别走n/2+1 如果是奇数,左右上下分别为n/2+1或者n/2+2 两种情况要累加 A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal directions: north, south, west, and east. For t

我见青山多妩媚,料青山见我应如是 315

基于YOLOv11的军事目标识别系统设计与实现(坦克、舰船检测)

DOTA-v2.0(包含多种军事装备的航拍图像)图片数量:11,268类别:18类,包括坦克、舰船、战斗机等分辨率:800×800~4000×4000HRSC2016(高分辨率舰船检测数据集)图片数量:1,061类别:舰船及子类特点:包含多种视角和复杂背景图片数量:5,000+类别:22种军用飞机标注:精确边界框自建数据集建议收集来源:公开军事演习视频、卫星图像、模拟游戏截图数据增强:模拟不同天气、遮挡、低光照等战场环境。

YOLO 450

微信小程序 - [wxapplib]] backgroundfetch privacy fail {“errno”:101,“errMsg”:“private_getBackgroundFetchDa

微信小程序报错之backgroundfetch privacy fail,微信小程序报错WAServiceMainContext.js:1 [wxapplib]] backgroundfetch privacy fail {“errno“:101,怎么解决?问题出现:调用wx.chooseMessageFile报错(开发者工具中正常)用户隐私协议中未声明小程序使用此功能,安卓真机调试报错:backgroundfetch privacy fail ,怎么解决?微信小程序[wxapplib]] backgrou

🏆 前端领域优质创作者 1万+

AtCoder Regular Contest 089 D - Checker

题目大意: " role="presentation" style="position: relative;">\quad 现有一个二维平面,并定义一个名词“ K" role="presentation" style="position: relative;">KKK 单位块” ;“ K" role="presentation" style="position: relative;">KKK 单

XzzF1024的博客 612

【系统分析师】2025年下半年真题:案例分析-答案及详解(回忆版)

Redis相比Memcached在电商高并发场景下具有显著优势:支持持久化(RDB/AOF)、丰富数据结构(如有序集合实现排行榜)、原生支持集群和哨兵模式(高可用性)。布隆过滤器通过位数组和哈希函数预先存储所有合法订单ID,当查询请求到达时快速拦截无效ID(如伪造ID),避免其穿透缓存直接冲击数据库,从而预防缓存击穿问题。

数据知道的博客 5982

Codeforces 1459 B. Move and Turn(有意思的数学题)

A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly 1 meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four directions, b

tomjobs的博客 1201

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Checker(AtCoder-3876)

Problem Description AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted blac...

Alex_McAvoy的博客 408

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

A. Robot Program

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is an infinite 2-dimensional grid. The robot stands in cell(0,0)(0,0)and wants to reach cell(x,y)(x,y). Here is a list of possibl...

无知的我 738

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

UASCO checker, 不要满足惯性思维

<br />Frankly speaking,第一眼看这个题真没劲,古董题,N皇后。不过,第一次提交代码之后我明白了,是我自己太没专研精神了。N皇后是回溯或者说深度优先搜索的典范,我就是初学回溯和DFS时接触到N皇后的,所以我飞敲键盘写出了下面的代码(这个不是直接提交的代码,是后

左手为你画情 2457

问题 J: Simple Knapsack

问题 J: Simple Knapsack时间限制: 1 Sec  内存限制: 128 MB提交: 65  解决: 24[提交][状态][讨论版][命题人:admin]题目描述You have N items and a bag of strength W. The i-th item has a weight of wi and a value of vi.You will select som...

Acerkoo的博客 459

AtCoDeer and Rock-Paper

6474: AtCoDeer and Rock-Paper 时间限制:1 Sec内存限制:128 MB提交:133解决:82[提交][状态][讨论版][命题人:admin] 题目描述 AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns...

weixin_30420305的博客 232

AtCoDeer and Election Report 二分

6473: AtCoDeer and Election Report 时间限制:1 Sec内存限制:128 MB 提交:316解决:82 [提交][状态][讨论版][命题人:admin] 题目描述 AtCoDeer the deer is seeing a quick report of election results on TV. Two...

weixin_30871701的博客 243

[思维]Ants on a Circle

题目描述 There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. O...

dingfei496705的博客 241

Star sky CodeForces - 835C (二维前缀和)

Star sky CodeForces - 835C The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi...

codeswarrior的博客 1080

Intense Heat(暴力+前缀和)

Intense Heat The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormal...

codeswarrior的博客 517
上一篇: AtCoder Regular Contest 088 D - People on a Line(DFS+图论)
下一篇: Palindrome
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值