hash--1264--与前类似

hdu的为你推荐相关题目 还真TM相关啊...

这题 又是用hash数组标记来做的 水题啊 明天 有时间的话 随便换换来做

      touch  me

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 
 5 const int size = 105;
 6 int hash[size+5][size+5];
 7 
 8 int main()
 9 {
10     cin.sync_with_stdio(false);
11     bool flag = false;
12     int i , j , a , b , c , d , cnt;
13     while( cin >> a >> c >> b >> d )
14     {
15         cnt = 0;
16         memset( hash , false , sizeof(hash) );
17         for( i = min(a,b)+1 ; i<=max(a,b) ; i++ )
18             for( j = min(c,d)+1 ; j<=max(c,d) ; j++ )
19                 hash[i][j] = true;
20         while(1)
21         {
22             cin >> a >> c >> b >> d;
23             if( a==-1 && b==-1 && c ==-1 && d==-1 )
24                 break;
25             else if( a==-2 && b==-2 && c==-2 && d==-2 )
26             {
27                 flag = true;
28                 break;
29             }    
30             for( int i = min(a,b)+1 ; i<=max(a,b) ; i++ )
31             {
32                 for( int j = min(c,d)+1 ; j<=max(c,d) ; j++ )
33                 {
34                     if( !hash[i][j] )
35                         hash[i][j] = true;
36                 }
37             }
38         }
39         for( int i = 0 ; i<=size ; i++ )
40         {
41             for( int j = 0 ; j<=size ; j++ )
42             {
43                 if( hash[i][j] )
44                 {
45                     cnt++;
46                 }
47             }
48         }
49         cout << cnt << endl;
50         if( flag )
51             break;
52     }
53     return 0;
54 }
View Code
just follow your heart
原文地址:https://www.cnblogs.com/radical/p/3872220.html