Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
太简单,都没人讨论- -//poj2306 #include<stdio.h> #define MAXN 1010 int X[MAXN]; int R, n; void read_data(int n); void solve(void); int main(int argc, char* argv[]) { while(scanf("%d %d", &R, &n) && R != -1) { read_data(n); solve(); } } void read_data(int n) { int temp; for(int i = 0; i < MAXN; ++i) X[i] = 0; for(int i = 0; i < n; ++i) { scanf("%d", &temp); X[temp] = 1; } } void solve(void) { int ans = 0; int start, mid, end; for(int i = 0; i < MAXN; ++i) { if(X[i] != 0) { ans++; start = i; mid = i + R; while(X[mid] == 0) mid--; for(int j = start; j <= mid+R; j++) X[j] = 0; } } printf("%d\n", ans); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator