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

二分水题,开2000ms干嘛呢,47ms水果

Posted by KatrineYang at 2016-08-29 11:50:47 on Problem 2318
#include <iostream>
#include <stdio.h>
using namespace std;

int U[5100], L[5100];
int S, T, N;

bool isZuo(int x, int y, int num){
	return S*(U[num]-x) > y*(U[num]-L[num]);
}

int main() {
	while(1){
		scanf("%d", &N);
		if(N == 0) break;
		int M, x1, y1, x2, y2;
		scanf("%d%d%d%d%d", &M, &x1, &y1, &x2, &y2);
		int temp = y1;
		y1 = y2;
		y2 = temp;
		S = y2 - y1, T = x2- x1;
		//cout << S << " " << T << endl;
		U[0] = 0, L[0] = 0;
		U[N+1] = L[N+1] = T;
		for(int i = 1; i <= N; i++){
			scanf("%d%d", &L[i], &U[i]);
			L[i] -= x1, U[i] -= x1;
		}
		int bin[5100] = {0};
		for(int i = 0; i < M; i++){
			int x , y;
			scanf("%d%d", &x, &y);
			x -= x1, y -= y1;
			int zuo = 0, you = N+1;
			while(you-zuo > 1){
				int mid = (zuo+you)/2;
				if(isZuo(x, y, mid)){
					you = mid;
				}
				else zuo = mid;
			}
			//printf("%d: %d\n", i, zuo);
			bin[zuo]++;
		}
		for(int i = 0; i <= N; i++){
			printf("%d: %d\n", i, bin[i]);
		}
		printf("\n");
 	}
	return 0;
}

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