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 idead at 2015-09-07 16:55:52 on Problem 1036
// Gangsters.cpp : 定义控制台应用程序的入口点。
//

#include "math.h"
#include <iostream>
using namespace std;
void swap(int*a ,int*b);
int main()
{
	int tmax, N, K, T, Tn[100], Pn[100], Sn[100], Fn[100], i, j, n;
		cin >> N >> K >> T;
		for (i = 0; i < N; i++) cin >> Tn[i];
		for (i = 0; i < N; i++) cin >> Pn[i];
		for (i = 0; i < N; i++) cin >> Sn[i];
		int imin, idx;
		for (i = 0; i < N; i++)
		{
			imin = 30001;
			for (j = i; j < N; j++)
			{
				if (Tn[j] <= imin)
				{
					imin = Tn[j];
					idx = j;
				}
			}
			swap(&Tn[idx], &Tn[i]);
			swap(&Pn[idx], &Pn[i]);
			swap(&Sn[idx], &Sn[i]);
		}
		for (i = 0; i < N; i++)
		{
			Fn[i] = (Tn[i] < Sn[i]) ? 0 : Pn[i];
		}
		for (n = 1; n < N; n++)
		{
			for (i = n; i < N; i++)
			{
				tmax = 0;
				for (j = 0; j < i; j++)
				{
					(Fn[j]>tmax&&abs(Tn[i] - Tn[j]) >= abs(Sn[i] - Sn[j])) ? tmax = Fn[j]: tmax;
					
				}
				Fn[i] = tmax + ((Tn[i] < Sn[i]) ? 0 : Pn[i]);
			}
		}
		tmax = 0;
		for (i = 0; i < N; i++)
		{
			(tmax < Fn[i]) ? tmax = Fn[i] : tmax;
		}
		cout << tmax;
	return 0;
}
void swap(int*a, int*b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

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