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

AC代码,二分查找

Posted by zxj1015 at 2015-06-20 22:46:05 on Problem 3388
#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:
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