2020牛客国庆集训派对day3 Leftbest

本文介绍了一种用于约会应用中的照片评分算法实现方法。通过跟踪并计算每张照片的真实印象分来评估用户的整体努力程度。文章提供了两种代码实现方案:一种超时的朴素方法和一种高效的利用C++ STL set容器的方法。

题面

链接:https://ac.nowcoder.com/acm/contest/7830/A
来源:牛客网

题目描述
Jack is worried about being single for his whole life, so he begins to use a famous dating app. In this app, the user is shown single men/women’s photos one by one, and the user may choose between “yes” and “no”. Choosing “yes” means an invitation while choosing “no” means nothing. The photos would be shown one by one until the number of rest photos to be shown reaches zero. Of course, efficient and single Jack would always choose “yes”.

When viewing photos, Jack would have a “fake impression point” on every photo, which is not accurate. To calculate the “true impression point” of one photo, Jack would recall the “fake impression point” of every previous photo whose “fake impression point” is larger than this photo, and regard the smallest “fake impression point” of them as the “true impression point” of this photo. Jack would like to sum the “true impression point” of all photos as the outcome of his effort.

Note that if such a larger “fake impression point” does not exist, the “true impression point” of this photo is zero.
在这里插入图片描述

示例1
输入
4 2 1 4 3
输出
6

超时代码

#include<stdio.h>
int cb[100009];
int main()
{
	int n;
	scanf("%d",&n);
	{
		long long ans = 0;
		int min = 0;
		for(int i=0 ; i<n ; i++){
			scanf("%d",&cb[i]);
			min = 99991177;
			int qq = 0;
			for(int j=0 ; j<i ; j++){
				if(cb[j] > cb[i] && min > cb[j]){
					min = cb[j];
				}
			}
			if(min == 99991177){
				min = 0;
			}
			ans += min;
		}
		printf("%lld\n",ans);
	}
}

通过代码

#include<bits/stdc++.h>
using namespace std;
set<int>cb;
int main()
{
	int n;
	long long ans = 0;
	
	cb.clear();
	scanf("%d",&n);
	for(int i=0 ; i<n ; i++){
		int q;
		scanf("%d",&q);
		if(cb.upper_bound(q) != cb.end())
		ans += *cb.upper_bound(q);
		
		cb.insert(q);
	}
	printf("%lld\n",ans);
}

解释

使用STL中的set集合即可很快过题

头文件: #include<set>

简单用法:

  • clear()    删除set容器中的所有的元素
  • empty()     判断set容器是否为空
  • begin()    返回set容器的第一个元素的地址
  • size()     返回当前set容器中的元素个数
  • end()     返回指向容器最后一个数据单元+1的指针,如果我们要输出最后一个元素的值应该是 *(–c.end());

set中有这样一个函数:

  • upper_bound(int x)     返回容器中第一个比x大的数字的地址,找不到则返回end()

集合还有着元素不重复,并且元素自行升序排列的特点

题目思路:
每次输入的时候查找第一个比x大的数字,有则加到ans,无论有或者没有都加入集合,循环到结尾后输出ans即可

内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置与长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式与逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取与解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维与验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析与算法验证,深入理解每一步的推理依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值