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 KatrineYang at 2016-07-02 16:25:24 on Problem 1065
//============================================================================
// Name        : main1065.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int MAX_INT = 2147483647;

class stick{
public:
	int l;
	int w;
	stick(int L, int W): l(L), w(W){}
	stick(): l(0), w(0){}
};

bool operator>(stick& s1, stick& s2){
	if(s1.l > s2.l) return true;
	if(s1.l < s2.l) return false;
	return s1.w >= s2.w;
}

int partion(stick *array, int p, int r) {
		stick x = array[r];
		int i = p - 1;//注意这点,把i设成负值,然后作为移动的标志
		int j;
		for (j = p; j < r; j++) {
			if (array[j] > x) {
				i++;
				stick temp = array[j];
				array[j] = array[i];
				array[i] = temp;
			}
		}
		stick temp = array[j];
		array[j] = array[i + 1];
		array[i + 1] = temp;
		return i+1;//返回的应该是交换后的哨兵的位置
}
		//递归解决每个划分后的小
void quickSort(stick *array, int p, int r) {
		if (p < r) {
			int q = partion(array, p, r);
			quickSort(array, p, q - 1);
			quickSort(array, q + 1, r);
		}
}


int main() {
	int cases;
	cin >> cases;
	for(int ii = 0; ii < cases; ii++){
		int st;
		cin >> st;
		stick sticks[5000];
		for(int i = 0; i < st; i++){
			cin >> sticks[i].l >> sticks[i].w;
		}
		quickSort(sticks, 0, st-1);
		int mei = st;
		bool state[5000] = {false};
		int res = 0;
		while(mei > 0){
			int curL = MAX_INT, curW = MAX_INT;
			for(int i = 0; i < st; i++){
				if(state[i]) continue;
				if(sticks[i].l <= curL && sticks[i].w <= curW){
					state[i] = true;
					curL = sticks[i].l;
					curW = sticks[i].w;
					mei--;
				}
			}
			res++;
		}
		cout << res << endl;
	}
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	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