Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题一道,鉴定完毕 附暴力代码

Posted by yousiki at 2016-07-25 08:53:07 on Problem 2189
题意:
给出1~P区间内的N个点,请找出最长的一段连续**区域**,使得区域内(包括边界)的点数不超过C。
注意的是,求出的区域是两个坐标之间的部分,例如:3~4是一个区间,包含3、4两个坐标。

分析:
数据范围很小,只有1000。
我仿佛看到人在跟我说:快暴力!快暴力!

代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1005;
int n, p, c;
int Cow[N], ans = 0;
signed main(void) {
	memset(Cow, 0, sizeof(Cow));
	scanf("%d%d%d", &n, &p, &c);
	for (int i = 1, pos; i <= n; i++)
		scanf("%d", &pos), Cow[pos]++;
	for (int i = 1; i < p; i++) {
		int j = i, sum = 0;
		while (j <= p&&sum <= c)
			sum += Cow[j++];
		ans = max(ans, j - i - 1);
	}
	printf("%d\n", ans);
//	system("pause");
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator