问题 B: a Simple Problem
时间限制: 1 Sec 内存限制: 128 MB
提交: 412 解决: 99
[提交][状态][讨论版]
题目描述
Many people think hh is a diaosi, but hh is a very rich man whose nickname is wenzhoutuhao,and he made a lot of money by buying the stock of neusoft. He bought n diamonds.One day he found that his warehouse is too small to accommodate these diamonds. so he decide to transfer c of the diamonds to another warehouse.He made the n diamonds into a row, with a number written on their positions, the number is the value of the diamond,the unit is billion(oh no so rich man),then,hh tells you to choose c diamonds,which will be sent to other warehouse,he also imposed two conditions.They are:
1.the chosen c diamonds must be formed a contiguous
segment
2.any of the chosen diamond’s value should not be greater than t,because he thought you may be would steal them.Find the number of ways you can choose the c diamonds.
输入
50 group tests,the first line of input will contain three space separated integer n(1<=n<=10^5),t(0<=t<=10^9) and c(1<=c<=n)
the next line will contain n space separated integer,the ith integer is the value of ith diamond,the value will be non-negative and will not be exceed 10^9
输出
print a single integer——the number of ways you can choose the c diamonds
样例输入
4 3 3 2 3 1 1 1 1 1 2
样例输出
2 0
提示
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { #ifdef CDZSC_OFFLINE freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); #endif int n,t,c,i,a[100050],p; while(scanf("%d%d%d",&n,&t,&c)!=EOF) { memset(a,0,sizeof(a)); int sum=0,k=1; for(i=1; i<=n; i++) { scanf("%d",&p); if(p>t) { a[k++]=i; } } a[k++]=n+1; if(k-2==0) { printf("%d\n",n-c+1); } else if(k-2==n) { printf("0\n"); } else { for(i=1; i<k; i++) { if(a[i]-a[i-1]-1>=c) { sum+=(a[i]-a[i-1]-1-c+1); } } printf("%d\n",sum); } } return 0; }