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 when at 2017-01-30 14:54:53 on Problem 3069
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN=1000+5;

int a[MAXN];

int solve(int N,int R){
    int i=0;
    int ans=0;
    while(i<=1000){

        while(a[i]==0&&i<=1000){
            i++;
        }
        if(i>1000)
            break;
        if(a[i]+R>=1000){
            ans++;
            break;
        }
        i=i+R;
        while(a[i]==0)
            i--;
        ans++;
        i=i+R+1;
    }
 return ans;
}

int main(){
 int N,R;
    while(cin>>R>>N){
        if(R==-1&&N==-1)
            break;
        memset(a,0,sizeof(a));
        for(int i=0;i<N;i++){
            int tmp;
            cin>>tmp;
            a[tmp]=1;
        }
    cout<<solve(N,R)<<endl;
    }
}


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