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 |
AC代码,二分查找#include <stdlib.h> #include <stdio.h> #include <vector> #include <queue> #include <stack> #include <string> #include <set> #include <map> #include <algorithm> #include <cmath> #include <utility> #include <set> #include <functional> #include <string.h> #include <iostream> #include <numeric> #include <list> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<int> data(k); for (int i = 0; i < k; ++i) { scanf("%d", &data[i]); } int low = 1; int high = n + 1; while (high - low > 1) { int mid = (high + low) / 2; int cols = 0; for (int i = 0; i < k; ++i) { cols += data[i] / mid; } if (cols >= n) { low = mid; } else { high = mid; } } printf("%d\n", low); for (int i = 0; i < k; ++i) { for (int j = data[i] / low; j > 0; --j) { // 注意这里一定要加上! if (n-- > 0) { printf("%d\n", i + 1); } else { break; } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator