版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载。

https://blog.csdn.net/kenden23/article/details/25105267

You are given an N × N grid initially filled by zeros. Let the rows and columns of the grid be numbered from1 to N, inclusive. There are two types of operations can be applied to the grid:

  • RowAdd R X: all numbers in the row R should be increased by X.
  • ColAdd C X: all numbers in the column C should be increased by X.

Now after performing the sequence of such operations you need to find the maximum element in the grid.

Input

The first line of the input contains two space separated integers N and Q denoting the size of the grid and the number of performed operations respectively. Each of the following Q lines describe an operation
in the format described above.

Output

Output a single line containing the maximum number at the grid after performing all the operations.

Constraints

  • 1 ≤ N ≤ 314159
  • 1 ≤ Q ≤ 314159
  • 1 ≤ X ≤ 3141
  • 1 ≤ R, C ≤ N

Example

Input:
2 4
RowAdd 1 3
ColAdd 2 1
ColAdd 1 4
RowAdd 2 1 Output:
7
原题:
http://www.codechef.com/problems/ROWCOLOP

非常好的题目,巧妙地计算终于结果。

注意: 

1 行列分开计算,最后组合最大值就是答案了, 不用搜索二维表

2 仅仅须要记录行列的终于结果就能够。不用模拟全过程

3 数据量非常大,处理输入问题

以下程序0ms通过。全站点本题最好答案,呵呵。

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h> class RowAndColumnOperations
{
static const int MAX_BU = 5120;
int st, len;
char buffer[MAX_BU]; char getFromBuffer()
{
if (st >= len)//st <= len? ?? Really? more careful!!!
{
len = fread(buffer, 1, MAX_BU, stdin);//forget len=?? ? st = 0;
}
return buffer[st++];
} char getCharFromBuf()
{
char c = getFromBuffer();
while (len)
{
if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') return c;
c = getFromBuffer();
}
return '0';
} int getInt()
{
char c = getFromBuffer();
while ((c < '0' || '9' < c) && len)
{
c = getFromBuffer();
}
int num = 0;
while ('0' <= c && c <= '9' && len)
{
num = (num<<3) + (num<<1) + (c - '0');
c = getFromBuffer();
}
return num;
} public:
RowAndColumnOperations() : st(0), len(0)
{
int N, Q, RC, addNum, MaxC = 0, MaxR = 0;
N = getInt()+1;
int *rows = (int *) malloc(sizeof(int) * N);
int *cols = (int *) malloc(sizeof(int) * N);
memset(rows, 0, sizeof(int) * N);
memset(cols, 0, sizeof(int) * N); Q = getInt();
char Commands[7];
while (Q--)
{
for (int i = 0; i < 6; i++)
{
Commands[i] = getCharFromBuf();
}
RC = getInt();
addNum = getInt();
if (Commands[0] == 'R')
{
rows[RC] += addNum;
MaxC = MaxC < rows[RC] ? rows[RC] : MaxC;
}
else
{
cols[RC] += addNum;
MaxR = MaxR < cols[RC] ? cols[RC] : MaxR;
}
}
printf("%d", MaxC + MaxR);
free(rows);
free(cols);
}
}; int rowAndColumnOperations()
{
RowAndColumnOperations();
return 0;
}

codechef Row and Column Operations 题解的更多相关文章

  1. LeetCode 947. Most Stones Removed with Same Row or Column

    原题链接在这里:https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/ 题目: On a 2D plane ...

  2. Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.

      1: /// <summary> 2: /// Write an algorithm such that if an element in an MxN matrix is 0, it ...

  3. excel小技巧-用于测试用例的编号栏:“获取当前单元格的上一格的值+1”=INDIRECT(ADDRESS(ROW()-1,COLUMN()))+1

    编写用例的时候使用,经常修改用例的时候会需要增加.删除.修改条目,如果用下拉更新数值的方式会很麻烦. 1.使用ctrl下拉,增删移动用例的时候,需要每次都去拉,万一列表比较长,会很麻烦 2.使用ROW ...

  4. Flutter 布局(七)- Row、Column详解

    本文主要介绍Flutter布局中的Row.Column控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. 1. Row A widget that displays its children ...

  5. params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

    params.row[params.column.key] vue h函数 当前单元格 h函数 div 属性 值或数组 render

  6. Flutter 布局类组件:线性布局(Row和Column)

    前言 所谓线性布局,即指沿水平或垂直方向排布子组件.Flutter中通过Row和Column来实现线性布局,并且它们都继承自弹性布局(Flex). 接口描述 Row({ Key key, // 表示子 ...

  7. 12.Quick QML-QML 布局(Row、Column、Grid、Flow和嵌套布局) 、Repeater对象

    1.Row布局 Row中的item可以不需要使用anchors布局,就能通过行的形式进行布局. 并且item可以使用Positioner附加属性来访问有关其在Row中的位置及其他信息. 示例如下所示, ...

  8. 陈年佳酿之 - Winform ListView 控件 double click 事件中获取选中的row与column

    背景 最近收到了一个关于以前项目的维护请求,那时的楼主还是刚刚工作的小青年~~~ 项目之前使用的是.net/winform.今天重新打开代码,看着之前在FrameWork2.0下面的代码, 满满的回忆 ...

  9. [Swift]LeetCode947. 移除最多的同行或同列石头 | Most Stones Removed with Same Row or Column

    On a 2D plane, we place stones at some integer coordinate points.  Each coordinate point may have at ...

随机推荐

  1. 深度学习之PyTorch实战(1)——基础学习及搭建环境

    最近在学习PyTorch框架,买了一本<深度学习之PyTorch实战计算机视觉>,从学习开始,小编会整理学习笔记,并博客记录,希望自己好好学完这本书,最后能熟练应用此框架. PyTorch ...

  2. Spring之Bean的配置方式

    在博客中为了演示容器Bean实例化时暴露出的几个接口,将UserBean配置在XML中,其实常见的Bean的配置有3种.1.基于xml配置Bean 2.使用注解定义Bean 3.基于java类提供Be ...

  3. EF SaveChanges() 报错(转载)

    最佳答案 报这个错是因为,提交了主键重复的数据,虽然未提交到数据库中 但是现在的EF上下文中已经包含了我提交的数据,下次在提交正确数据时, 原来添加到上下文中的数据依然还在..如何处理这个问题呢?   ...

  4. 有道云笔记链接——JAVA面向对象的学习

     http://note.youdao.com/noteshare?id=cf39a0e493a6b3c7ad5d22204a7e7843

  5. Git实战手册(三): stash解惑与妙用

    0. 介绍 教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 在实际项目开发中,总会遇到代码写到一半(没法去打commit),去开启新 ...

  6. vue点击元素变色兄弟元素不变色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. linux基础学习之软件安装以及常用命令

    linux基础学习之软件安装以及常用命令 调用中央仓库: yum install wget 然后下载nodejs: wget https://nodejs.org/dist/v10.14.2/node ...

  8. python中文编码&json中文输出问题

    python2.x版本的字符编码有时让人很头疼,遇到问题,网上方法可以解决错误,但对原理还是一知半解,本文主要介绍 python 中字符串处理的原理,附带解决 json 文件输出时,显示中文而非 un ...

  9. Google Chrome 中安装 PostMan 扩展

    简介 PostMan 是调试 HTTP 请求的好工具,也是业界的佼佼者,这对于我们开发 Web Service 提供了很好的调试入口,支持请求认证机制.最关键的是,这个工具提供 Google Chro ...

  10. 【代码笔记】Web-JavaScript-JavaScript 变量

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...