HDU--4324 -- Trouble

Source: Internet
Author: User

HDU--4324 -- Trouble

// Take an exam. Divide the five intervals into 200*200,200*200,200. Note: Use _ int64 as the pass (output: % I64d)

AC code:

 

#include
 
  #include
  
   #include
   using namespace std
   ;#define N 205
   __int64 num
   [6
   ][N
   ];__int64 s0
   [N
   *N
   ];__int64 s1
   [N
   *N
   ];__int64 s2
   [N
   ];int main(){    int x
   ;    scanf
   (%d
   ,&x
   );    while(x
   --)    {        int n
   ;        scanf
   (%d
   ,&n
   );        int i
   ,j
   ;        for(i
   =1
   ;i
   <=5
   ;i
   ++)        {            for(j
   =1
   ;j
   <=n
   ;j
   ++)            {                scanf
   (%I64d
   ,&num
   [i
   ][j
   ]);            }        }        int cnt
   =0
   ;        for(i
   =1
   ;i
   <=n
   ;i
   ++)        {            for(j
   =1
   ;j
   <=n
   ;j
   ++)            {                s0
   [cnt
   ++]=num
   [1
   ][i
   ]+num
   [2
   ][j
   ];            }        }        int l0
   =cnt
   ;        cnt
   =0
   ;        for(i
   =1
   ;i
   <=n
   ;i
   ++)        {            for(j
   =1
   ;j
   <=n
   ;j
   ++)            {                s1
   [cnt
   ++]=num
   [3
   ][i
   ]+num
   [4
   ][j
   ];            }        }        int l1
   =cnt
   ;        cnt
   =0
   ;        for(i
   =1
   ;i
   <=n
   ;i
   ++)        {            s2
   [cnt
   ++]=num
   [5
   ][i
   ];        }        int l2
   =cnt
   ;        sort
   (s0
   ,s0
   +l0
   );        sort
   (s1
   ,s1
   +l1
   );        sort
   (s2
   ,s2
   +l2
   );        int ok
   =0
   ;        int k
   ;        for(i
   =0
   ;i
   <l2
   &&ok
   ==0
   ;i
   ++)        {                j
   =0
   ,k
   =l0
   -1
   ;                while(j
   <l1
   &&k
   >=0
   )                {                    if((s0
   [k
   ]+s1
   [j
   ]+s2
   [i
   ])==0
   )                    {                        ok
   =1
   ;                        break;                    }                    else if((s0
   [k
   ]+s1
   [j
   ]+s2
   [i
   ])>0
   )                    {                        k
   --;                    }                    else                    {                        j
   ++;                    }                }        }        if(ok
   )        {            printf
   (Yes
   );        }        else        {            printf
   (No
   );        }    }    return 0
   ;}
  
 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.