Hdoj/hdu 2560 buildings (hmm ~ water problem)

Source: Internet
Author: User

Problem Description
We divide the hznu Campus into n*m grids. As can see from the picture below, the green grids represent the buidings. Given the size of the Hznu Campus, and the color of each grid, you should count how many green grids in the n*m grids.

Input
Standard input would contain multiple test cases. The first line of the input was a single integer T which is the number of test cases. T test Cases follow.
The first line of all test case contains, integers n and M (1<=n,m<=100), the size of the campus. Then follow n lines, each line containing M integers. The j-th integer in the i-th line is the color of this grid, 0 stands for white color, while 1 stands for green.

Output
Results should is directed to standard output. For each case, output a integers T, the total green grids in the n*m size campus.

Sample Input
2
2 2
1 1
0 0
3 3
1 0 1
0 0 1
1 1 0

Sample Output
2
5

Water Problem One ~ ~
is a school n*m area, then there are buildings ~
1 representing the building, statistics of the total number of buildings ~

Import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch);intT =sc.nextint (); while(t-->0){intn =sc.nextint ();intM =sc.nextint ();intsum=0; for(intI=0; i<n;i++) { for(intj=0; j<m;j++) {inta =sc.nextint ();if(a==1) {sum++; }}} System. out. println (sum); }    }}

Hdoj/hdu 2560 buildings (hmm ~ water problem)

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.