Saturday, September 22, 2018

Non-empty subset

  • Problem Description

    Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0.
    Input
    The first line of input contains T - number of test cases. 
    Each of the next T lines containing four pairwise distinct integer numbers - a, b, c, d.
    Output
    For each test case output ""Yes"", if possible to get 0 by choosing non-empty subset of {a, b, c, d} with sum equal 0, or ""No"" in another case.
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int a,b[100],i,j,d=0;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        for(j=0;j<4;j++)
           scanf("%d",&b[j]);
      if(b[0]==0||b[1]==0||b[2]==0||b[3]==0)
        d=d+1;
        else if(b[0]==-b[1]||b[0]==-b[2]||b[0]==-b[3]||b[1]==-b[2]||b[1]==-b[3]||b[2]==-b[3])
          d=d+1;
        else
          d=0;
        if(d>0)
          printf("Yes\n");
        else
          printf("No\n");   
      }
    return 0;
    }
  • Test Case 1

    Input (stdin)
    3
    
    1 2 0 3
    
    1 2 4 -1
    
    1 2 3 4
    
    
    Expected Output
    Yes
    
    Yes
    
    No
  • Test Case 2

    Input (stdin)
    2
    
    2 4 5 1
    
    2 2 3 2
    
    
    Expected Output
    No
    
    No

1 comment:

  1. GRSoft Gaming is an honor winning, Live Casino game advancement organization of India. We offer curiosity and inventive game development with an exceptionally talented group of developer. Our bleeding edge gaming innovation creates esteem included gaming arrangements. Quality is our real worry for club game development. We offer tweaked Casino game development benefits over the globe and help you furnish with customized development. With our Casino game, individuals couldn't imagine anything better than to chance their gaining and appreciate the advantages. We have created numerous effective games like the video poker game, Sports wagering game, online club game, lottery games, and numerous other common games.

    Casino Games Software Developers UK, USA - Casino Game Development UK, USA

    ReplyDelete