uva 10131 - Is Bigger Smarter?

Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ’s are decreasing.

Input

The input will consist of data for a bunch of elephants, one elephant per line, terminated by the endof-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.

Output

Say that the numbers on the i-th data line are W[i] and S[i]. Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing an elephant). If these n integers are a[1], a[2],..., a[n] then it must be the case that   W[a[1]] < W[a[2]] < ... < W[a[n]]  and  S[a[1]] > S[a[2]] > ... > S[a[n]]

In order for the answer to be correct, n should be as large as possible. All inequalities are strict: weights must be strictly increasing, and IQs must be strictly decreasing.

There may be many correct outputs for a given input, your program only needs to find one.

Sample Input

6008 1300

6000 2100

500 2000

1000 4000

1100 3000

6000 2000

8000 1400

6000 1200

2000 1900

Sample Output

4

4

5

9

7

 

题意:找出一段不需按照原定顺序的子列使其满足条件

排序一次然后再最小上升(或下降)子序列

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n=1,m,w[1005],s[1005],dp[1005],lat[1005];
struct B{
	int w,s,id;
}a[1005];
bool cmp(B i,B j)
{
	if(i.s == j.s)
	  return i.w < j.w ;
	return i.s > j.s ;
}
void ready()
{
	ios::sync_with_stdio(false),cin.tie(0);
	while(cin>>a[n].w >>a[n].s)
	{
		a[n].id=n;
		n++;
	}
	n--;
	sort(a+1,a+n+1,cmp);
 
}
void work_for_w()
{
	dp[1]=1; 
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			if(a[i].w>a[j].w && dp[j]+1>dp[i])
			{
				dp[i]=dp[j]+1;
				lat[i]=j;
			}
		}
	}
	int k=0,ans=0;
	for(int i=1;i<=n;i++)
	  if(dp[i]>dp[k])
	    k=i;
	while(k)
	{
		dp[++ans]=a[k].id;
		k=lat[k];
	}
	cout<<ans<<endl;
	for(int i=ans;i>=1;i--)
	  cout<<dp[i]<<endl;
}
int main()
{ 
	ready();
	work_for_w();
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用和引用[2]提到了一个错误信息"1153 - Got a packet bigger than 'max_allowed_packet' bytes",这是当MySQL客户端或mysqld服务器接收到超过max_allowed_packet字节的信息包时会发出的错误。具体来说,这个错误表示接收到的数据包的大小超出了MySQL配置文件中设置的最大允许大小。这个错误可能会导致插入或导入数据时失败。 要解决这个问题,可以按照以下三个步骤进行操作: 1. 修改MySQL配置文件中的max_allowed_packet值。这个值控制着服务器接收的最大数据包大小。可以通过编辑配置文件(通常是my.cnf或my.ini)并将max_allowed_packet的值增加到足够大的大小来解决这个问题。 2. 重启MySQL服务以使配置更改生效。 3. 重新尝试执行引发错误的操作。现在,MySQL服务器应该能够处理更大的数据包并成功执行操作。 需要注意的是,确保将max_allowed_packet的值设置为适当的大小,以便不会过分消耗服务器资源,并确保操作的成功执行。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [[Err] 1153 - Got a packet bigger than 'max_allowed_packet' bytes(linux环境).pdf](https://download.csdn.net/download/lvlei19911108/20838930)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Linux下mySQL报错:[Err] 1153 - Got a packet bigger than ‘max_allowed_packet‘ bytes](https://blog.csdn.net/happyzhlb/article/details/127533306)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Naviacat导入sql文件时MySQL报错 Error 1153 - Got a packet bigger than ‘max_allowed_packet‘ bytes](https://blog.csdn.net/weixin_44905544/article/details/127978822)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值