IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) 653C Bear and Up-Down(暴力)

c语言【分糖果】2023蓝桥杯4124(枚举,递归,dfs) 但是这是不符合我们糖果刚好分完的条件的,我们应该往回退到上一层,也就是孩子6这层,然后j+1=3,孩子7分到3个第二种糖果,这也不符合我们糖果刚好分完的条件,然后就会再次回退到孩子6这里,然后j+1=4,让我们的孩子7获得5块第二种糖果,然后还是不符合糖果刚分完的条件,于是再一次退回到孩子6这里,然后就会有外循环i+1=1,j=1,孩子7分到1块第一种糖果1块第二块糖果......然后就是这样的不停地回溯,试探,直到把整棵树遍历一遍,并且记录所有的满足条件的组合。先放一下我的代码,我的代码超时啦救命! 阅读详情

C. Bear and Up-Down
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:

  • ti < ti + 1 for each odd i < n;
  • ti > ti + 1 for each even i < n.

For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.

Bear Limak has a sequence of positive integers t1, t2, ..., tn. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements ti and tj in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.

Output

Print the number of ways to swap two elements exactly once in order to get a nice sequence.

Examples
input
5
2 8 4 7 7
output
2
input
4
200 150 100 50
output
1
input
10
3 2 1 4 1 4 1 4 1 4
output
8
input
9
1 2 3 4 5 6 7 8 9
output
0
Note

In the first sample, there are two ways to get a nice sequence with one swap:

  1. Swap t2 = 8 with t4 = 7.
  2. Swap t1 = 2 with t5 = 7.

In the second sample, there is only one way — Limak should swap t1 = 200 with t4 = 50.




题目链接:点击打开链接

给出n个数的序列, 对任意奇下标要小于后一个, 任意偶下标大于后一个, 可以交换一次, 问有多少种复合题意的方法.

暴力枚举, 记录不符合题意的位置, 暴力交换两个位置的数进行判断, 判断时只需判断交换位置的两个数以及不符合题意数的位置.

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
#define X first
#define Y second
#define exp 1e-8
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 15e4 + 5;
int n, a[MAXN], ans;
bool flag[MAXN];
std::vector<int> v;
bool Judge(int x)
{
	int val = a[x];
	if(x & 1) {
		if(x < n && val >= a[x + 1]) return false;
		if(x > 1 && val >= a[x - 1]) return false;
	}
	else {
		if(x < n && val <= a[x + 1]) return false;
		if(x > 1 && val <= a[x - 1]) return false;
	}
	return true;
}
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i)
		if(!Judge(i)) {
			v.push_back(i);
			flag[i] = true;
		}
	if(v.size() > 10) {
		printf("0\n");
		return 0;
	}
	for(auto x : v) 
		for(int y = 1; y <= n; ++y)
			if(!flag[y] || y > x) {
				swap(a[x], a[y]);
				bool valid = Judge(x) && Judge(y);
				for(auto z : v) 
					if(!Judge(z)) valid = false;
				if(valid) ans++;
				swap(a[x], a[y]);
			}
	printf("%d\n", ans);
	return 0;
}


2万字长文:海豚调度器(DolphinScheduler)面试题深入了解 DAG图(有向无环图)是海豚调度器中表示工作流任务依赖关系的一种方式。在DolphinScheduler中,每个任务是一个节点,任务之间的依赖关系通过有向边连接这些节点来表示。无环:保证了工作流的执行顺序是确定的,避免了无限循环的问题。有向:箭头指示了任务的执行方向,即上一个任务的输出可以作为下一个任务的输入。依赖表示:通过图形化界面,用户可以通过拖拽连接线来定义任务之间的先后顺序和依赖关系。并行处理:DAG图可以表示出任务的并行关系,允许多个任务在没有直接依赖关系的情况下同时执行。条件分支。 阅读详情

相关推荐

Python 打包与发布陷阱:如何用 setuptools 和 PyInstaller 生成跨平台可执行文件?

使用。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1207

CF# IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C - Bear and Up-Down

诶呀,其实这是一道水题,水题,水题! 真的哩,大家想想暴力怎么做=。=,然后大家就应该都会了! 题意: 一个nice的数列 对于奇数位 必须满足ai#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<stdlib.h> #include<

qq_24664053的博客 489

PPL文档——Excel制作的甘特图加上动态今日线

当很多项目需要跟踪进度时,我们介绍一种在Excel中创建甘特图。

qq_34777858的博客 7064

Codeforces 653C - Bear and Up-Down 暴力

C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The life goes up and down, just like nice sequ...

253

【机器学习入门】1.4 吃透这些基本术语,才算真正入门

本文通过"挑西瓜"的生活案例,形象解释了机器学习的基本术语。样本对应单个西瓜,特征如色泽、根蒂等是观察维度,特征值是其具体表现,标签是西瓜的好坏判断。数据集是样本集合,特征向量是样本的数学表达,特征空间是所有可能的样本组合。文章强调数据集需划分为训练集、验证集和测试集,以评估模型的泛化能力。最后整理了术语对照表,并解答了常见问题。这些基础概念是理解机器学习的关键,建议读者重点掌握。

国科大硕士在读,分享Python/GEE/Matlab/R专业代码实践,涵盖数据分析、算法开发与应用技巧等,以代码会友。 655

从“要啥”到“咋测”:手把手拆解Aspice SWE.1需求分析,为你的车载/嵌入式项目避坑

本文深入解析Aspice SWE.1需求分析在车载/嵌入式项目中的关键作用,帮助开发者将模糊的系统需求转化为可执行、可验证的软件需求。通过实战案例和结构化方法,详细拆解功能需求原子化、非功能需求工程化表达等核心技巧,为项目避坑提供实用指南。

weixin_31682031的博客 259

Codeforces(653C)-C. Bear and Up-Down

原题链接 C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The life goes up and down, ju

L. 633

从Simulink仿真到DSP28335真机部署:PID闭环控制快速移植指南

本文详细介绍了如何将Simulink中的PID闭环控制算法快速移植到DSP28335嵌入式平台。通过模型与代码映射、浮点与定点数选择、定时器中断配置、物理输出实现以及调试技巧五个关键步骤,帮助工程师高效完成从仿真到真机部署的全过程,特别适合需要实现精确控制的嵌入式开发者。

weixin_42521843的博客 363

IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down【模拟】

/* *********************************************** Author :Maltub Email :xiang578@foxmail.com Blog :htttp://www.xiang578.top ************************************************ */#

禅境花园 583

问题解决:打开VMware创建的虚拟机,电脑立刻蓝屏并重启

VMware Workstation 与 Device/Credential Guard 不兼容。在禁用 Device/Credenti

weixin_55118477的博客 3万+

美团外卖 mtgsig 1.2 逆向工程与补环境实战指南

本文深入解析了美团外卖核心风控参数mtgsig 1.2的生成机制与逆向实战。通过拆解其复杂的JSON结构,揭示了设备指纹、环境信息加密等关键字段。重点阐述了在Node.js中模拟浏览器环境(补环境)的核心方法,包括DOM/BOM对象、本地存储及Canvas/WebGL等高级指纹的模拟技巧,为安全研究和合规自动化测试提供了一套完整的技术指南。

uber9的博客 410

Codeforces 653C Bear and Up-Down【暴力】

题目链接: http://codeforces.com/problemset/problem/653/C 题意: 给定序列,偶数位的数字比两边都大,则成为nice,只可以交换两个数字,问有多少种交换方式使得最后的序列为nice。 分析: 比赛的时候找规律,找呀找了好久都没看出来。。。。由于只可以交换一次,交换两个数字,所以最多改变的6个数字的关系。那...

An55511的博客 244

乐鑫科技 EchoEar 喵伴修改自定义唤醒词的方法 EchoEar喵伴、唤醒词修改、ESP32、AI萌宠、智能音箱、开发者指南

标签:乐鑫科技、EchoEar喵伴、唤醒词修改、ESP32、AI萌宠、智能音箱、开发者指南大家好,我是一名前端开发工程师,最近在玩乐鑫科技推出的时,发现它不仅萌趣十足,还能进行全双工语音交互、多模态识别,甚至能识别你的情绪和与你互动。EchoEar 喵伴是由乐鑫科技和火山引擎扣子大模型团队合作开发的,它使用乐鑫的芯片方案(ESP32 系列)+ 火山引擎扣子大模型,支持 WiFi 连接和本地处理,长记忆能力可以让它记住用户的偏好与习惯。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1888

IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)-C - Bear and Up-Down-暴力枚举

http://codeforces.com/contest/653/problem/C 题意: 给n,给n个数。 要求一个合法序列满足: 偶数项>奇数项,奇数项 给一个序列,要求交换仅一对数,使得原序列变成合法序列 问你有多少种方案 扫一遍 看有多少个位置不符合要求,也就是  偶数项《奇数项,奇数项》偶数项的,我们把后一项坐标记录起来。 如果这样的坐标如果超过

缺氧 640

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力

C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two ...

weixin_34348174的博客 195

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Codeforces 653C Bear and Up-Down【暴力+思维】题目还不错~

C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The life goes up and down, just like nice sequenc

mengxiang000000 729

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Codeforces Round #321 (Div. 2) 580C Kefa and Park(dfs)

题目链接: 第一行给你n、m,接下来的一行有n个数,如果为1则代表这个点有cat,接下来的n-1行每行给出x、y,表示x、y相连。问你从1出发 能到达的叶子结点有几个,要求到达叶子结点的路上连续有cat的点不超过m。 a数组保存结点是否含有cat,从1这个点开始dfs,每次dfs对cat数组操作,记录连续的含有cat的点数,回溯时再判断当前结点是否满足 条件,要求结点为叶子

GKHack's Blog 2041

Codeforces Round #200 (Div. 2)344E Read Time(二分)

E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mad scientist Mike does not use slow hard disks

GKHack's Blog 1749

Codeforces Round #325 (Div. 2) 586ABC题解

题目链接:点击打开链接 A: 给出Alena的课表, 1代表有课, 0代表没课, 2个连续0以上可以回家休息, 问你一天在学校待多久. 直接模拟即可, 可以直接计算1, 101的数目. 我记录了开头的1和结尾的1, 然后减去2个连续0以上的个数就是答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #

GKHack's Blog 1711

Codeforces Round #308 (Div. 2)题解

第二天补的 并不都是自己写的 参考了别人的题解 感觉这次cf题意好懂 就是做起来嘛。。 毕竟我还太弱。。 只为落实 A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input

GKHack's Blog 1674

Codeforces Round #322 (Div. 2) 581A 581B 581C

581A链接:点击打开链接 给你a只红袜子,b只蓝袜子,问你可以组成多少对颜色不同的袜子以及剩下多少对单色袜子。 小小的脑洞,答案分别为a, b最小值以及a - b绝对值的一半。 AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1665

Codeforces Round #250 (Div. 2) 437C The Child and Toy(脑洞贪心)

C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output On Children's Day, the child got a toy

GKHack's Blog 1627

Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1617

Codeforces Round #315 (Div. 2)569C Primes or Palindromes?(预处理)

C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that t

GKHack's Blog 1599

Codeforces Round #201 (Div. 2) 347C Alice and Bob(脑洞)

C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It is so boring in the summer holiday, isn

GKHack's Blog 1584

Manthan, Codefest 16 633C Spy Syndrome 2(dfs + stl)

C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After observing the results of Spy Syndro

GKHack's Blog 1574
上一篇: Codeforces Round #344 (Div. 2) 631C Report(脑洞+stl)
下一篇: IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) 653B Bear and Compressing(dfs + stl)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值