hdu--1866--矩形重叠<扫描法,自定义>

擦  终于做出题了...........  这2天 没心思啊  烦 烦 ...

这题 虽然不难 但还是有地方要注意

可能会有空格存在 所以不能用cin scanf去读 一定要用getline  gets来读取

而且 可能会有除了题目中这些 ( ) , +这4个符号以为的字符 所以判断的时候 用!(ch>='0' && ch<='9')来判断

因为 数据很小的啊 才1000  整个扫过去就是了 用个标记变量数组vis表示 是否被扫过了 然后一块格子一块格子++来计算总面积

...........晚上 cf 能让我出C D吗 敢不敢!

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 
 6 const int size = 520;
 7 char str[size];
 8 int matrix[size];
 9 bool vis[size*2][size*2];
10 bool judge( char ch )
11 {
12     if( ch>='0' && ch<='9' )
13         return false;
14     return true;
15 }
16 
17 int main()
18 {
19     int i , len , cnt , ans;
20     while( gets(str) )
21     {
22         ans = i = 0;
23         cnt = 1;
24         len = strlen(str);
25         memset( matrix , 0 , sizeof(matrix) );
26         memset( vis , false , sizeof(vis) );
27         while( i<len )
28         {
29             if( judge(str[i]) )
30             {
31                 i++;
32             }
33             else
34             {
35                 while(1)
36                 {
37                     if( judge(str[i]) )
38                         break;
39                     matrix[cnt] = matrix[cnt]*10+(str[i]-'0');
40                     i++;
41                 }
42                 cnt ++;
43             }
44         }
45         for( int i = 0 ; i<cnt/4 ; i++ )
46         {
47             int x1 = matrix[i*4+1];
48             int y1 = matrix[i*4+2];
49             int x2 = matrix[i*4+3];
50             int y2 = matrix[i*4+4];
51             int maxX = max(x1,x2);
52             int maxY = max(y1,y2);
53             for( int x = min(x1,x2)+1 ; x<=maxX ; x++ )
54             {
55                 for( int y = min(y1,y2)+1 ; y<=maxY ; y++ )
56                 {
57                     if( !vis[x][y] )
58                     {
59                         vis[x][y] = true;
60                         ans ++;
61                     }
62                 }
63             }
64         }
65         cout << ans << endl;
66     }
67     return 0;
68 }
View Code

好像 2天没更新叻 =-=

today:

  少年谈爱与不爱 成年人谈和谐不和谐

just follow your heart
原文地址:https://www.cnblogs.com/radical/p/3915547.html