E. Restoring the Permutation

E. Restoring the Permutation

在这里插入图片描述
在这里插入图片描述

Example

input

4
7
3 3 4 4 7 7 7
4
1 2 3 4
7
3 4 5 5 5 7 7
1
1

output

3 1 4 2 7 5 6 
3 2 4 1 7 6 5 
1 2 3 4 
1 2 3 4 
3 4 5 1 2 7 6 
3 4 5 2 1 7 6 
1 
1 

题目大意:

给一个非严格升序的数组,替换第一次出现后后面再出现的重复数字,使得1-n的每个数字只出现一次,分别求字典序最大和最小的序列。

思路:

字典序较小的比较好求:统计出现重复数字的空,用1-n没出现过的数字,从小到大填进去。

求字典序较大的序列:统计出现重复数字的空,填进去比当前数字小的最大的数,要是用朴素法枚举,复杂度就可以卡到N*N,所以得想办法把复杂度降到N,用set的lower_bound可以轻易做到,差不多是N * logN。

代码:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+7;

int a[N];
int b[N];
bool check[N];
bool check2[N];
set<int>s;

signed main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		int k=1;
		cin>>n;
		for(int i=1;i<=n;++i)s.insert(i);//先都装进去
		for(int i=1;i<=n;++i)
		{
			cin>>a[i];
			b[i]=a[i];
			if(check[a[i]])
			{
				a[i]=k;
				check[k]=1;
			}
			else
			{
				check[a[i]]=1;
			}
			while(check[k])++k;
			if(s.find(b[i])!=s.end())
				s.erase(b[i]);//出现的就不能用来填了,所以删掉
		}
		for(int i=1;i<=n;++i)
		{
			if(check2[b[i]])
			{
				b[i]=*prev(s.lower_bound(b[i]));//lower求第一个大于等于b[i]的数,它的前一个就是比b[i]小的最大的数
				s.erase(b[i]);
			}
			else
			{
				check2[b[i]]=1;
			}
		}
		for(int i=1;i<=n;++i)
		{
			cout<<a[i]<<' ';
			a[i]=0;
		}
		cout<<endl;
		for(int i=1;i<=n;++i)
		{
			cout<<b[i]<<' ';
			b[i]=0;
			check[i]=0;//顺便初始化
			check2[i]=0;
		}
		cout<<endl;
		s.clear();
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
翻译This SiO2 shell is a key component in the mechanism for reversible actuation, as illustrated by finite element analysis (FEA) in Fig. 1C. An increase in temperature transforms the SMA (nitinol) from the martensitic to the austenitic phase, causing the 3D structure to flatten into a 2D shape. The responses of the SMA elements at the joints act as driving forces to deform the PI skeleton. This process also elastically deforms the SiO2 shell, resulting in a counter force that limits the magnitude of the deformation. The change in shape ceases when the forces from the shell balance those from the joints (right frame in Fig. 1C). Upon a reduction in temperature, the SMA changes from the austenitic back to the martensitic phase, thereby reducing the force produced by the SMA at the joints to zero. The elastic forces associated with the shell then push the entire system back to the original 3D geometry (left frame in Fig. 1C). Figure S3A simulates the moments generated by the SMA and the SiO2 shell. In the FEA model, the SiO2 shell appears on both the outer and inner surfaces of the 3D robot, consistent with experiments (fig. S3B). Although a single layer of the SiO2 shell at the outer or inner surface can also provide restoring force, the double-layer shell structure follows naturally from the conformal deposition process. This actuation scheme allows for reversible shape transformations using a one-way shape memory material. Without the shell, the structure only supports a single change in shape, from 3D to 2D, as illustrated in fig. S3C. Figure 1D shows optical images of a freestanding 3D peekytoe crab on the edge of a coin, highlighting the preserved 3D geometry enabled by the SiO2 shell after release from the elastomer substrate. Other 3D structures in geometries that resemble baskets, circular helices, and double-floor helices also exhibit high shape storage ratios (>85%) after cycles of heating and cooling (fig. S4). This ratio (s) is defined as s = 1 − |L1 − L0|/L0 × 100%, where L0 and L1 are the distances between the bonding sites at both ends at the initial stage and subsequent stages, respectively
最新发布
06-13

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值