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 |
Re:贪心大水题In Reply To:贪心大水题 Posted by:13408100238 at 2014-08-08 08:56:45 #include <iostream> #include <vector> #include <algorithm> using namespace std; int R, N; int main() { while (cin >> R >> N) { vector<int> data; if (R == -1 && N == -1) break; int x; for (int i = 0; i < N; i++) { cin >> x; data.push_back(x); } sort(data.begin(), data.end()); int i = 0, ans = 0; while (i < N) { int s = data[i++]; while (data[i] <= s + R && i < N)i++; int p = data[i - 1]; while (data[i] <= p + R && i < N)i++; ans++; } cout << ans << "\n"; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator