m0_61115814 2023-04-04 22:18 采纳率: 66.7%
浏览 12
已结题

遇到的困难(c++)

今天在做题的时候遇到了一些我不太能解决的困难,请大家们帮我解决一下

#include <stdio.h>
using namespace std; 
struct NODE {
    int X1,X2,Y1,Y2;//X coordinate and y coordinate
    int width,lengh;//The length and width of a rectangle
};
int cnt=0;
struct NODE a[1024];
int n;//numbers of the coordinates
int main(int args,char **argc) {
    scanf("%d",&n);//input n
    for(int i=0;i<n;i++) {
        scanf("%d %d %d %d",&a[i].X1,&a[i].Y1,&a[i].X2,&a[i].Y2);//input the coordinates
        a[i].width=a[i].Y2-a[i].Y1;// Rectangular width
        a[i].lengh=a[i].X2-a[i].X1;//Rectangular length
        cnt+=a[i].lengh*a[i].width; 
    }
    printf("%d",cnt);
    return 0;
}
#if 0
input
2
2 2 9 5
6 1 12 9
output
60

#endif


img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-04-04 22:29
    关注

    估计是要考虑矩形重叠的部分,只涂一次

    我个人建议,因为数据量不大,可以考虑定义一个500x500的数组,初始化为0,然后把所有输出的区域都标记为1
    最后统计所有为1的有多少。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月13日
  • 已采纳回答 4月5日
  • 创建了问题 4月4日

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题