2018山东省赛E题 Sequence

本文介绍了一个算法问题,即如何通过删除一个元素使得排列中的“好数”数量最多。所谓“好数”是指在序列中一个元素大于其之前所有元素的情况。文章提供了具体的解题思路与代码实现。

Sequence

Time Limit: 1000 ms  Memory Limit: 65536 KB
Problem Description

We define an element a_iai in a sequence "good", if and only if there exists a j(1\le j < i)j(1j<i) such that a_j < a_iaj<ai.
Given a permutation pp of integers from 11 to nn. Remove an element from the permutation such that the number of "good" elements is maximized.

Input

The input consists of several test cases. The first line of the input gives the number of test cases, T(1\le T\le 10^3)T(1T103).
For each test case, the first line contains an integer n(1\le n\le 10^6)n(1n106), representing the length of the given permutation.
The second line contains nn integers p_1,p_2,\cdots,p_n(1\le p_i\le n)p1,p2,,pn(1pin), representing  the given permutation pp.
It’s guaranteed that \sum n\le 2\times 10^7n2×107.

Output

For each test case, output one integer in a single line, representing the element that should be deleted. If there are several answers, output the minimal one.
 

Sample Input
2
1
1
5
5 1 2 3 4
Sample Output
1
5

题意:在一个数列中,假如一个数比在它之前出现的任意一个数大,那么它是一个好数,现在必须删去一个数,使剩余的数好数最多,多个解输出最小值.

思路:当时思路是看看每个数删去之后会减少多少好数,假如一个数前面比他小的只有一个,那么删去那个数这个数也就不再是好数,所以我们可以看看比当前数小的是不是只出现了一个,是的话那个最小值的度++.开始想写树状数组,后来想起来维护一个次小值即可.

此处可以交题

代码:

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const double esp = 1e-12;
const int inf = 0x3f3f3f3f;
map<int,int>::iterator it;

int n;
int a[maxn],d[maxn];

int main()
{
	int t;
	scanf("%d",&t);
	
	while(t--)
	{
		mem(d,0);
		scanf("%d",&n);
		for(int i = 1;i<= n;i++)
			scanf("%d",&a[i]);
		
		int minx1 = inf,minx2;//最小值和次小值
		for(int i = 1;i<= n;i++)
		{
			if(a[i]> minx1) d[a[i]]++;//是好数自己度++
			if(a[i]> minx1&&a[i]< minx2)
				d[minx1]++;//前面有唯一的比他小的值,那个数的度++
			if(a[i]< minx1)
				minx2 = minx1,minx1 = a[i];//更新最小次小值
			else minx2 = min(minx2,a[i]);//更新次小值
		}
		
		int ans,ansd = inf;
		for(int i = 1;i<= n;i++)
		{
			if(d[a[i]]< ansd)
				ansd = d[a[i]],ans = a[i];
			else if(d[a[i]] == ansd)
				ans = min(ans,a[i]);
		}
		
		printf("%d\n",ans);
	}
	
	return 0;
}


Bad climate change may greatly increase the fragility of the country. How to evaluate the impact of climate change and mitigate the impact of climate change has become an urgent problem. With regard to task one, a data envelopment analysis (DEA) model is established to get the country's fragility. First of all, we selected 4 climate factors as input indicators and 5 output indicators. Then, we use the entropy method to determine the weight and then the national vulnerability is divided. At the same time, we get the conclusion that temperature affects GDP and the times of armed conflict directly and affects the fragility indirectly. In view of task two, we choose Somalia as an object of study. First, all the indexes are divided into 5 levels by the method of cluster analysis. Second, we select 10 countries including Somalia, to solve the decision unit matrix. Then, using the model of the problem one, it is found that the increase in temperature and rainfall will cause the national vulnerability to rise and decrease, respectively. Finally, we assign 4 climate indicators to 0 of the decision units, and draw the conclusion that national vulnerability will be reduced without the impact of climate factors. When it comes to task three, we use the rough set theory to reduce the output index to the number of armed conflicts. Then, we use the BP neural network model to predict the conclusion: There is a significant increase in fragility in cases of much more armed conflict and abnormal temperature. When the average annual armed conflict is certain, the national vulnerability index will face an increasing turning point at the temperature of 10.01 and the rainfall of 1823mm. As to task four, three policies on energy reduction and emission reduction issued by the government have been selected, and a model of carbon cycle is established. Taking China as an example, we calculate the extent of the change of the average temperature by reducing the carbon dioxide emissions from the state, and calculate the change of the national vulnerability through the change of temperature. We conclude that when the temperature drops 1.9 degrees, the national vulnerability decreases by 0.1593 and the cost is 20.3 billion $. Last but not least, due to the relative accuracy of the DEA model, the urban fragile performance is accurately predicted while the continent is not. In this paper, the TOPSIS model of distance entropy of three parameter interval number is used to modify the decision matrix of the DEA model. By increasing the upper and lower bounds of the interval, the value of the decision unit is more accurate, and then the weight of the index is modified based on the schedule. When we use the North American continent for test, the error was about 2.9%。 主要解决国家脆弱性的问,欢迎下载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值