Description

Ziyao has a big drawing board with N * M squares. At the beginning, all the squares on the board are white, represented by the number 0. We can see the 4 * 4 whilte drawing board is:

0000

0000

0000

0000

One day Ziyao wants to draw on the board. He will draw  for T times. Each time he will draw a rectangle with the color he like.For each rectangle, we use 4 integers (x1, y1, x2, y2) to express it. It means all squares whose coordinate (x, y)  exist both x1 <= x <=x2 and y1 <= y <= y2. If two rectangles are intersected, the intersected part will be covered by the color later drawing.

For example, if he draw a rectangle (1, 2, 3, 3) on the white board with the color ‘1’, the board will be:

0110

0110

0110

0000

And if he go on drawing a rectangle (2, 1, 3, 2) by ‘2’, the board will be:

0110

2210

2210

0000

Now, Ziyao Big God will tell you his drawing process, please tell me how many colors will be there on the board.

Input

The first line has 3 integers, N, M, T.(0 < N, M <= 100, 0 <= T <=20)

The next T lines, each line has 5 integers x1, y1, x2, y2, c, (x1, y1, x2, y2) express the rectangle and c is the color.(1 <= x1, x2 <= N, 1 <= y1, y2 <=M, 1 <= c <= T)

Output

Just one number, how many colors on the board.

PS:’0’ is also a kind of color.

Sample Input 1

4 4 2

1 2 2 3 1

2 1 3 2 2

Sample Input 2

4 4 2

1 1 1 1 2

1 1 4 4 1

Sample Output 1

3

Sample Output 2

1

Hint

For the first sample, the board is

0110

2210

2200

0000

There are 3 colors:0,1,2.

For the second sample, the board is

1111

1111

1111

1111

There are only 1 color: 1.

这道题的话还好,主要注意的是题目的第一行或者列是数组下标为0的时候,这里要注意,还有就是怎么算出总共的颜色有多少种,我是另外开个数组,然后有数字的就做上标记

我的

#include<stdio.h>
int a[100][100] = {0};
int main() {
int n, m, t;
int b[200] = {0};
int x1, y1, x2, y2, c, sum = 0, flag = 0;
scanf("%d %d %d", &n, &m, &t);
while (t--) {
scanf("%d %d %d %d %d", &x1, &y1,&x2, &y2, &c);
x1 -= 1;
x2 -= 1;
y1 -= 1;
y2 -= 1;
for (int i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
a[i][j] = c;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int temp = a[i][j];
b[temp]++; }
}
for (int i = 0; i < 200; i++) {
if (b[i] != 0)
sum++;
}
printf("%d", sum);
return 0;
}

  

标程(思想差不多)

1.#include <stdio.h>
2.int n, m, t, a[100][100], i, j, ans;
3.int main() {
4. int x1, y1, x2, y2, c, colors[21];
5. scanf("%d%d%d", &n, &m, &t);
6. for (i = 0; i < n; i++)
7. for (j = 0; j < n; j++) a[i][j] = 0;
8. while (t--) {
9. scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
10. for (i = x1; i <= x2; i++)
11. for (j = y1; j <= y2; j++)
12. a[i - 1][j - 1] = c;
13. }
14. for (i = 0; i <= 20; i++) colors[i] = 0;
15. for (i = 0; i < n; i++)
16. for (j = 0; j < m; j++)
17. colors[a[i][j]] = 1;\\原来是可以这样的
18. ans = 0;
19. for (i = 0; i <= 20; i++) ans += colors[i];
20. printf("%d", ans);
21. return 0;
22.}

  

[2013 Final] Colors的更多相关文章

  1. Amazon Hiring Campus 2013 - Final 6

    Let's assume that there is a simple market for beans. Every day there is a published bean price in t ...

  2. LOJ#2764. 「JOI 2013 Final」JOIOI 塔

    题目地址 https://loj.ac/problem/2764 题解 真的想不到二分...不看tag的话... 考虑二分答案转化为判定问题,那么问题就变成了能不能组合出x个JOI/IOI,考虑贪心判 ...

  3. javascript继承笔记

    //原型(prototype):原型是一个对象,其他对象可以通过它实现属性继承 /*笔记: * 1.类式继承:通过原型链继承的方式 * 2.原型式继承:对类式继承的封装 * 3.寄生式继承:对原型继承 ...

  4. JavaScript原型链和继承

    1.概念 JavaScript并不提供一个class的实现,在ES6中提供class关键字,但是这个只是一个语法糖,JavaScript仍然是基于原型的.JavaScript只有一种结构:对象.每个对 ...

  5. 阅读《JavaScript设计模式》第二章心得

    面向对象编程 面向对象编程就是将你的需求抽象成一个对象.然后针对这个对象分析其特征(属性)与动作(方法).这个对象我们称之为类.面向对象编程思想其中的一个特点就是封装. 1.私有属性.私有方法.特权方 ...

  6. 「题解」:[loj2763][JOI2013]现代豪宅

    问题 A: 现代豪宅 时间限制: 1 Sec  内存限制: 256 MB 题面 题目描述 (题目译自 $JOI 2013 Final T3$「現代的な屋敷」) 你在某个很大的豪宅里迷路了.这个豪宅由东 ...

  7. 「CSP-S模拟赛」2019第三场

    目录 T1 「POI2007」山峰和山谷 Ridges and Valleys 题目 考场思路(几近正解) 正解 T2 「JOI 2013 Final」 现代豪宅 题目 考场思路(正解) T3 「SC ...

  8. Integrating SharePoint 2013 with ADFS and Shibboleth

    Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...

  9. [.net 面向对象程序设计深入](3)UML——在Visual Studio 2013/2015中设计UML活动图

    [.net 面向对象程序设计深入](3)UML——在Visual Studio 2013/2015中设计UML活动图 1.活动图简介 定义:是阐明了业务用例实现的工作流程. 业务工作流程说明了业务为向 ...

随机推荐

  1. Android软件更新安装。

    app的开发有一个问题是避免不了的,那就是软件的升级维护. 这里我在查过一些资料和写了一个升级帮助类.使用很方便.直接导入就可以了. ( VersionBean.class为更新地址返回的数据对象,我 ...

  2. Excel—“撤销工作表保护密码”的破解并获取原始密码

    您是否遇到过这样的情况:您用Excel编制的报表.表格.程序等,在单元格中设置了公式.函数等,为了防止其他人修改您的设置或者防止您自己无意中修改,您可能会使用Excel的工作表保护功能,但时间久了保护 ...

  3. VMware 中windows server 之DHCP 搭建与测试

    感悟: 由于打算将windows server 的服务器搭建维护从头重新学习总结一下,遇到搭建dhcp服务的时候,在虚拟机中一直测试不成功,耽误我好几星期了,一点也不夸张,心情和积极性也大大受到打击. ...

  4. c# winform 打包部署 自定义界面 或设置开机启动

    添加安装部署项目后,鼠标右键安装项目->视图->注册表, 要使软件在开机就运行,可以在HKEY_CURRENT_USER\Software\Microsoft\Windows\Curren ...

  5. C++ 类里面,函数占用存储空间问题

    转载自:http://blog.163.com/xping_lsr/blog/static/19654034520119804131721/ 先看两段代码: 代码段1:class A{public:i ...

  6. magnum 命令使用说明

    magnum 命令使用说明 1.用法 usage: magnum [--version] [--debug] [--os-cache] [--os-region-name <region-nam ...

  7. iOS 原生态扫描二维码、条形码的功能。

    1.导入AVFoundatin.framework. 2.新建一个viewController,命名为QRScanViewController,用于扫描的界面. h文件如下,设置代理. #import ...

  8. Redis运维的一些常用的命令总结

    最近一直管理部门的一些redis的服务器,所以现在来总结一下redis的一些常用的运维命令: 1.time  显示服务器的时间,时间戳(秒) 微秒数 redis 127.0.0.1:6380> ...

  9. JavaScript 常用算法

    1.排序算法 (1)冒泡排序,冒泡排序其实就是通过比较相邻位置的元素大小,如果左边比右边大,就交换位置,继续比较,实际上就是每轮比较都得出一个最大值,然后通过多伦比较得出. function bubb ...

  10. c++学习笔记——字面值常量类

    字面值常量类:数据成员都是字面值类型的聚合类是字面值常量类.如果一个类不是聚合类,但是它符合一下要求,则它也是个字面值常量类: 1.数据成员都必须是字面值类型. 2.类必须至少含有一个constexp ...