杭电 1160

24 篇文章 1 订阅
21 篇文章 0 订阅

                                     FatMouse的速度

时间限制:2000/1000 MS(Java / Others)内存限制:65536/32768 K(Java /其他)
提交的总数:23267接受的提交内容:10355 
Special Judge

问题描述

FatMouse认为鼠标越胖,运行速度就越快。为了证明这一点,您希望将数据放在一组鼠标上,并将尽可能大的数据子集放入序列中,以便权重增加,但速度会降低。

输入

输入包含一堆鼠标的数据,每行一个鼠标,由文件末尾终止。
特定鼠标的数据将由一对整数组成:第一个以克为单位表示其大小,第二个以厘米每秒表示其速度。两个整数都在1到10000之间。每个测试用例中的数据将包含最多1000只小鼠的信息。
两只小鼠可以具有相同的重量,相同的速度,或甚至相同的重量和速度。

产量

你的程序应输出一系列数据; 第一行应包含数字n; 其余的n行应各包含一个正整数(每个整数代表一个鼠标)。如果这n个整数是m [1],m [2],...,m [n]则必须是
W [m [1]] <W [m [2]] <... < W [m [n]] 

S [m [1]]> S [m [2]]> ...> S [m [n]] 
为了使答案正确,n应该与可能。
所有不等式都是严格的:权重必须严格增加,速度必须严格降低。对于给定的输入,可能有许多正确的输出,您的程序只需要找到一个。

样本输入

6008 1300

6000 2100

500 2000

1000 4000

1100 3000

6000 2000

8000 1400

6000 1200

2000 1900

样本输出

4

4

9

7

这道题头一次写,能崩溃啊;  好不容易调通了,但是要求严格递增、递减,好在坚持住了

 

2000
4000
3000    len 2    par 1

1900        3    par 2
2100        3        2
2000        4        4

1200        5        5
1300
1400

#include<iostream>
#include<iomanip>
#include<algorithm> 
#include<cstring>
#include<sstream> 
#include<cmath>
#define ALL 10001
struct Mou{
	int weight;
	int speed;
	int parent;
	int beforeIndex;
}mouse[ALL];
bool compare(Mou a, Mou b){
	return a.weight < b.weight;
}
using namespace std;
int main()
{
	int count,currentIndex,minIndex,ansIndex,maxValue,tempIndex;
	int len[ALL],ans[ALL],lenIndex[ALL];
	count=0;
	while(cin >> mouse[count].weight >> mouse[count].speed){ 
		mouse[count].parent = -1;
		mouse[count].beforeIndex = count;
		len[count] = 0;
		count++;
	}
	sort(mouse,mouse+count,compare);
	len[0] = 1;
	for(int i=1; i<count; i++){
		minIndex = -1;
		maxValue = 0;
		for(int j=0; j<i; j++){
			if(mouse[j].speed > mouse[i].speed && len[j] > maxValue){
				maxValue = len[j];
				minIndex = j;	
			}
		}
		len[i] = maxValue + 1;
		mouse[i].parent = minIndex;
	}
	
	tempIndex = 0;
	for(int i=1; i<count; i++){
		if(len[i] > len[tempIndex])
			tempIndex = i;
	}
	int afterIndex = tempIndex + 1;
	int everMaxLen = 0,innerIndex,final;
	final = tempIndex;
	while(afterIndex < count){
		if(len[afterIndex] == len[tempIndex]){
			ansIndex = 0;
			innerIndex = afterIndex;
			while(mouse[innerIndex].parent != -1){
				currentIndex = innerIndex;
				innerIndex = mouse[innerIndex].parent;
				if(mouse[currentIndex].weight == mouse[innerIndex].weight || mouse[currentIndex].speed == mouse[innerIndex].speed){
				} else{
					ansIndex++;
				}
			}
			if(ansIndex > everMaxLen){
				final = afterIndex;
				everMaxLen = ansIndex;
			}
			
		}
		afterIndex++;
	}
	ansIndex = 0;
	tempIndex = final;
	ans[ansIndex] = tempIndex;
	while(mouse[tempIndex].parent != -1){
		currentIndex = tempIndex;
		tempIndex = mouse[tempIndex].parent;
		if(mouse[currentIndex].weight == mouse[tempIndex].weight || mouse[currentIndex].speed == mouse[tempIndex].speed){
		} else{
			ansIndex++;
			ans[ansIndex] = tempIndex;
		}
	}
	cout << ansIndex+1 << endl;
	for(;ansIndex>=0; ansIndex--)
		cout << mouse[ans[ansIndex]].beforeIndex + 1 << endl;
	
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值