Bad Hair Day(单调栈)

Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.

Each cow i has a specified height hi (1 ≤ hi ≤ 1,000,000,000) and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cow i can see the tops of the heads of cows in front of her (namely cows i+1, i+2, and so on), for as long as these cows are strictly shorter than cow i.

Consider this example:

        =
=       =
=   -   =         Cows facing right -->
=   =   =
= - = = =
= = = = = =
1 2 3 4 5 6 

Cow#1 can see the hairstyle of cows #2, 3, 4
Cow#2 can see no cow's hairstyle
Cow#3 can see the hairstyle of cow #4
Cow#4 can see no cow's hairstyle
Cow#5 can see the hairstyle of cow 6
Cow#6 can see no cows at all!

Let ci denote the number of cows whose hairstyle is visible from cow i; please compute the sum of c1 through cN.For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.

Input

Line 1: The number of cows, N.
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i.

Output

Line 1: A single integer that is the sum of c1 through cN.

Sample Input

6
10
3
7
4
12
2

Sample Output

5

单调栈的基础应用。

#include<stdio.h>
#include<stack>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		stack<int>kk;
		int x;
		cin>>x;
		kk.push(x);
		n=n-1;
		long long ans=0;
		while(n--)
		{
			cin>>x;
			while(!kk.empty()&&kk.top()<=x)
			kk.pop();
			ans+=kk.size();
			kk.push(x);
		}
		cout<<ans<<endl;
	}
	return 0;
}

 

<think>好的,我现在需要处理用户关于BSidesCF 2020 CTF比赛不佳体验的反馈请求。用户还提到了几个相关的题目,比如Had a bad day和Hurdles,这些题目需要特定的请求头、Cookie、参数构造等才能解决。首先,我需要分析用户的问题,确定他们的具体需求。 用户可能遇到了技术上的困难,比如题目中的各种限制条件,如IP地址、Cookie设置、请求头调整、参数编码等,导致无法顺利解题。他们可能对如何正确构造请求或绕过检查感到困惑。同时,用户提到参考了引用资料中的方法,但可能仍有疑问或需要进一步的解释。 接下来,我需要根据提供的引用信息,整理每个题目的关键解决步骤。例如,在Had a bad day中,利用PHP伪协议读取文件;在Hurdles中,设置多个请求头、Cookie以及处理俄语提示。需要将这些步骤清晰地呈现出来,帮助用户理解每一步的作用。 此外,用户可能希望了解如何系统地解决类似的CTF题目,包括如何分析题目要求、构造有效Payload、调试请求等。因此,回答中需要包含解题思路的通用方法,并结合具体例子进行说明,确保用户能够举一反三。 同时,要注意引用标记的正确使用,每个关键点后添加对应的引用来源。例如,在提到PHP伪协议时引用[5],在讨论请求头设置时引用[3]和[4]。这样不仅增加回答的可信度,也方便用户查阅原始资料。 最后,生成的相关问题需要覆盖用户可能感兴趣的其他方面,比如其他CTF题目的解法、工具推荐或学习资源,确保信息全面且实用。整个过程要保持回答结构清晰,语言简洁,符合中文表达习惯,避免使用复杂术语,必要时进行解释。</think>### BSidesCF 2020 CTF题目反馈与解题思路 #### 1. 题目难点与反馈 BSidesCF 2020的部分题目(如`Had a bad day`和`Hurdles`)因其复杂的条件限制和多层验证机制,可能导致解题体验不佳。以下是关键问题总结及解决方法: --- #### 2. 具体题目分析与解法 **题目1: [BSidesCF 2020] Had a bad day** - **目标**: 绕过文件包含限制,读取`flag.php`。 - **关键步骤**: 1. 发现URL参数`category`存在文件包含漏洞,但限制了文件路径必须包含`woofers`或`meowers`。 2. 利用PHP伪协议构造Payload,通过Base64编码读取文件内容: `php://filter/read=convert.base64-encode/woofers/resource=flag`[^5]。 3. 解码Base64内容即可获取Flag。 --- **题目2: [BSidesCF 2020] Hurdles** - **目标**: 通过多层HTTP请求验证。 - **关键条件与解法**: 1. **IP限制**: 客户端IP需为`13.37.13.37`,通过`X-Forwarded-For`头伪造[^4]。 2. **Cookie要求**: 设置`Fortune=6265`(RFC 6265为2011年HTTP状态管理标准)[^3]。 3. **语言与格式**: 添加`Accept:text/plain`和`Accept-Language:ru`绕过俄语提示[^3]。 4. **来源验证**: 添加`Origin`和`Referer`头指向指定域名。 5. **最终请求示例**: ```bash curl -X PUT 'http://...' -H 'X-Forwarded-For:13.37.13.37' -b 'Fortune=6265' -H 'Accept:text/plain' -H 'Origin:https://ctf.bsidessf.net' ``` --- #### 3. 通用解题建议 - **分析题目条件**: 仔细阅读返回的提示信息(如HTTP头、错误消息),定位验证逻辑。 - **分步验证**: 使用工具(如Burp Suite或Postman)逐步添加请求头/Cookie,观察响应变化。 - **编码与绕过**: 对特殊字符进行URL编码(如`%00`表示空字符),利用协议封装(如`php://filter`)绕过过滤[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值