UVa 1344-tian Ji-The Horse Racing

Source: Internet
Author: User

Sun Bin said: "Online practice is good trouble ...


Tips:

1. The topic is n<=1000, actually there is no need to go to pit O (n) greedy algorithm is it?

2. Enumeration I'm going to lose a few games, then the losing game according to Sun Bin's strategy must be with my worst of those horses to play the best horse son

3. Other horses must be matched in order of speed and size one by one to prove the method is not difficult to think, I started: Assuming that the first K has been well-matched, if at this time the speed of this one is less than the speed of the Zi Pang, then ...


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <algorithm>

using namespace std;
const int MAXN = 1100;

int n;
int A[MAXN];
int B[MAXN];

inline bool Judge (int D, int& Mon)
{
	mon = 0;
	for (int i=0;i<n-d;i++) if (A[i]>b[d+i]) return false; else mon+= (a[i]==b[d+i]?0:200);
	return true; 
}

int main (int argc, char *argv[]) {while
	
	(cin>>n && N)
	{for
		(int i=0;i<n;i++) cin> >b[i];
		for (int i=0;i<n;i++) cin>>a[i];
		Sort (A, a+n);
		Sort (b, b+n);
		
		int res =-(1<<29), Mon; 
		for (int i=0;i<=n;i++) if (judge (I, Mon)) res = max (res, mon-i*200);
		cout<<res<<endl; 
		
	}
	
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.