problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing1749 命名空间参考

  1. 阻挡广告牌 II
更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing1749, case1)
 
 TEST (acwing1749, case2)
 

详细描述

  1. 阻挡广告牌 II

函数说明

◆ main()

int acwing::acwing1749::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp6013 行定义.

6013 {
6014 int x1[2];
6015 int x2[2];
6016 int y1[2];
6017 int y2[2];
6018 for(int i = 0; i < 2; i++) {
6019 cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
6020 }
6021 const unsigned int area = abs(x2[0] - x1[0]) * abs(y2[0] - y1[0]);
6022 int x_1 = x1[1];
6023 int x_2 = x2[1];
6024 int y_1 = y1[1];
6025 int y_2 = y2[1];
6026 x_1 = max(x_1, x1[0]);
6027 x_2 = max(x_2, x1[0]);
6028 x_1 = min(x_1, x2[0]);
6029 x_2 = min(x_2, x2[0]);
6030 y_1 = max(y_1, y1[0]);
6031 y_2 = max(y_2, y1[0]);
6032 y_1 = min(y_1, y2[0]);
6033 y_2 = min(y_2, y2[0]);
6034 if(x_2 == x_1 || y_2 == y_1) {
6035 //没有遮盖
6036 cout << area;
6037 return 0;
6038 }
6039 if(y_2 == y2[0] && y_1 == y1[0]) {
6040 //纵向填满
6041 cout << abs(abs(x2[0] - x1[0]) - abs(x_2 - x_1)) * abs(y_2 - y_1);
6042 return 0;
6043 }
6044 if(x_1 == x1[0] && x_2 == x2[0] && (y_1 == y1[0] || y_2 == y2[0])) {
6045 //横向填满
6046 cout << (x_2 - x_1) * max(y2[0] - y_2, y_1 - y1[0]);
6047 return 0;
6048 }
6049 cout << area;
6050 return 0;
6051 }

被这些函数引用 TEST().

◆ TEST() [1/2]

acwing::acwing1749::TEST ( acwing1749  ,
case1   
)

在文件 acwing_test.cpp2831 行定义.

2831 {
2832 istringstream in("2 1 7 4\n"
2833 "5 -1 10 3");
2834 auto out = ostringstream();
2835 main(in, out);
2836 const auto ans = out.str();
2837 ASSERT_EQ("15", ans);
2838 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

acwing::acwing1749::TEST ( acwing1749  ,
case2   
)

在文件 acwing_test.cpp2840 行定义.

2840 {
2841 istringstream in("14 -783 421 693\n"
2842 "-153 680 443 741");
2843 auto out = ostringstream();
2844 main(in, out);
2845 const auto ans = out.str();
2846 ASSERT_EQ("595441", ans);
2847 }

引用了 main().