当前位置:网站首页>*3-2 CCF 2014-09-2 drawing
*3-2 CCF 2014-09-2 drawing
2022-08-09 14:51:00 【Ye Xiaobai】
题目描述
样例
源代码
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100;
int flag[N + 1][N + 1];
int main()
{
int n, x1, y1, x2, y2, sum = 0;
// 变量初始化
memset(flag, 0, sizeof(flag));
// 输入数据,计算处理
cin >> n;
for (int i = 1; i <= n; i++) {
// 输入数据
cin >> x1 >> y1 >> x2 >> y2;
// cumulative area
sum += (x2 - x1) * (y2 - y1);
// Mark and remove overlaps
for (int i = x1; i < x2; i++)
for (int j = y1; j < y2; j++) {
if (flag[i][j])
sum--;
flag[i][j] = 1;
}
}
// 输出结果
cout << sum << endl;
return 0;
}
关于这题
Because a grid has four points when counting repetitions It's easy to overcount
So here we use the number of points instead of the number of grids
(Boxed with squares are the marked points Circles represent repetitions need to be reduced)
边栏推荐
猜你喜欢
随机推荐
What is the cost of small program development and production?Three development methods cost analysis!
关于舵机的漂移与不听指挥乱动的问题
阿里巴巴云原生大数据运维平台 SREWorks 正式开源
汇编语言学习(五)
String为什么是不可变的?
【视频编码学习】——变换的理解
#25-1 OJ 78 计算生日星期几
RHCE课程总结
网安学习-应急响应3
RHCE课程总结
How to develop small programs?should focus on features
PerparedStatement防止SQL注入
dpkg:错误:无法新建文件 ‘/var/lib/dpkg/info/format-new’: 没
C语言 函数问题
C语言中的 pow 函数 使用方法及注意事项,和常见报错原因,且分享实战中的使用
*4-1 CCF 2014-12-1 Access Control System
C语言 最大公约数,最小公倍数(详细注释代码 一次解决)
apt-get install 和pip install 的区别
1.11 flink中的动态加载udf jar包
*5-2 CCF 2014-12-3 集合竞价