poj 3112 Digital Biochemist Circuit(简单题)

题目链接:http://poj.org/problem?id=3112

Digital Biochemist Circuit

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 876   Accepted: 375

Description

A digital biochemist circuit (DBC) is a device composed of a set of processing nodes. Each processing node consists of a small receptacle for holding biochemist agents. The receptacle is made of a biological substance that works like a digital circuit. Depending
on the states of reactions in the receptacle, the substance may generate two levels of voltage. A reader connected to a DBC is capable of reading all processing nodes of the DBC instantaneously, interpreting the two levels of voltage as 0 or 1.

An experiment with the DBC is carried out in the following way. The processing nodes are loaded with the substances of interest and appropriate reagents and, for every fixed time interval (typically several milliseconds), the voltage of processing nodes
are read. Thus, the experiment results in a sequence of bit sets (vectors), each corresponding to a measurement of the DBC.

A sequence of 1-bits uninterrupted throughout the time of a processing node is called a run. The length of a run is the number of 1-bits in the sequence (note that the length of runs of an experiment can vary between one and the number
of measurements made). One important characteristic of an experiment with the DBC is the number and length of the runs generated. The figure below shows the result of an experiment carried out with a DBC of six processing nodes, on which four measurements
are made, containing three runs of length one, one run of length two and one run of length four.

0 1 0 1 1 0
0 0 0 1 0 0
0 1 0 1 0 1
0 1 0 1 0 0

You are contracted to write a program that determines, given the result of an experiment, how many runs of length that is equal to or greater than a certain value are generated.

Input

The input contains several test cases. The first line of test case contains three integers PN and C which indicate the number of processing nodes (1 ≤ P ≤ 1000), the number of measurements made (1 ≤ N ≤ 1000)
and the minimum length of runs of interest (1 ≤ C ≤ N), respectively. Each of the next N lines contains P digits {0, 1} separated by a whitespace. The end of the input is indicated by P = N = C =
0.

Output

For each test case in the input your program should produce a single line of output, containing the number of runs of length greater than or equal to C produced by the experiment.

Sample Input

2 2 2
1 1
1 1
4 5 3
0 1 0 1
1 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
0 0 0

Sample Output

2
2

Source

South America 2006, Brazil Subregion

题目大意:统计每一列中连续为1的段大于等于p的数量;

具体见代码解析!

代码如下:

#include <cstdio>
#include <cstring>
int main()
{
	int n, m, p;
	int ans;
	int a[1017];
	int i, j;
    while (scanf("%d%d%d",&m, &n, &p))
    {
		memset(a, 0, sizeof(a));//初始化
		if(n == 0 && m == 0 && p == 0)
			break;
		ans = 0;
		int x;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < m; j++)
			{
				scanf("%d",&x);
				if(x)
					a[j]++; //统计同一列连续的个数
				else if(a[j] != 0)//间断
				{
					if(a[j] >= p)//计数
						ans++;
					a[j] = 0;//间断,重新开始计数
				}
			}
		}
		for(i = 0; i < m; i++)//最后还要做一次统计,因为有可能到最后也没有间断;
		{						//那么上面就没有统计到这种情况
			if (a[i] >= p)
				ans++;
		}
		printf("%d\n", ans);
    }
    return 0;
}

poj 3112 Digital Biochemist Circuit(简单题),布布扣,bubuko.com

时间: 2024-10-15 06:09:05

poj 3112 Digital Biochemist Circuit(简单题)的相关文章

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&

POJ 2405 Beavergnaw (计算几何-简单题)

Beavergnaw Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6203   Accepted: 4089 Description When chomping a tree the beaver cuts a very specific shape out of the tree trunk. What is left in the tree trunk looks like two frustums of a co

poj 3070 矩阵快速幂简单题

基本运用,基本是模板题. 求fi[n].       (1,1)    *( 1  ) ( 1,0)     (  0) #include<iostream> #include<cstring> using namespace std; struct juz { int bat[3][3]; int x,y; //行 列 }; juz mutp(juz a,juz b) { juz c; c.x=a.x;c.y=b.y; memset(c.bat,0,sizeof(c.bat));

POJ 3183 Stump Removal(简单题)

[题意简述]:就是这个树桩,当它比它身边的树桩都高的时候,他就能炸掉身边的树桩.现在让我们使用最少的炸药将所有树桩都炸掉,问这些炸弹都放在哪些树桩上. [分析]:简单的模拟一下,运用贪心法则,只要这个树桩比身边的其他树桩高,就输出它的位置即可. 但是,的确要注意一下边界的处理! //412K 516Ms #include<iostream> using namespace std; int Stump[50005]; int main() { int N; cin>>N; for(

POJ 2562 Primary Arithmetic(简单题)

[题意简述]:计算两数相加,有多少个进位. [分析]:很简单,不过还是要注意输出的细节.当进位为1时,输出的operation,没有s. 详见代码: // 216K 0Ms #include<iostream> using namespace std; int main() { int a,b; while(cin>>a>>b) { if(a == 0&&b == 0) break; // 在这贡献了n次WA~,傻! int ans = 0; int t

POJ 3300 Tour de France(简单题)

[题意简述]:由The drive ratio -- the ratio of the angular velocity of the pedals to that of the wheels -- is n : m where n is the number of teeth on the rear sprocket and m is the number of teeth on the front sprocket. Two drive ratios d1 < d2 are adjacent

POJ 2141 Message Decowding(简单题)

[题意简述]:这个题目描述非常简单,不再赘述. [分析]:直接把那个输入的字符,当做是key值数组的下标即可. //164K 16Ms #include<iostream> using namespace std; char Key[27]; char decoded [81]; int main() { gets(Key); gets(decoded); for(int i = 0;i<strlen(decoded);i++) { if(decoded[i]>='A'&&

POJ 1318 Word Amalgamation (简单题)

[题意简述]:首先第一串"XX--"之前的是所谓的字典,然后在它之后的就是我们要查的字串.现在让我们逐个求出这些要查的字串排列后和字典中的字串相同的有哪些,输出出来,没有的话就输出:NOT AVALLID WORD [分析]:理解很简单,我们只需分别对字典中的这些字符串,和我们要查的这些字符串,每一个都排序,然后按位比较,每一位都是相同的那就输出出来就好了. #include<iostream> using namespace std; int n; char word[1

POJ 2579 Blurred Vision(简单题)

[题意简述]:要以左上角的方块与它下方.右方以及右下方的值求平均值,将结果放入该方块即可. [分析]:由于数字都连在一块,所以只能使用字符型的变量来存储这个字符数组. 详见代码: //216K 0Ms #include<iostream> using namespace std; char map[10][10]; char start[15],end[15]; int main() { int r,c; while(1) { cin>>start; if(strcmp(start