Codeforces Round #549 (Div. 2)A. The Doors

本文介绍了一个有趣的编程问题,即在一系列门(代表左或右出口)中找到最快的逃离路径。通过遍历序列并跟踪左右出口门的状态,可以确定最早能够从任一出口离开的时刻。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

A. The Doors
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.

There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index kk such that Mr. Black can exit the house after opening the first kk doors.

We have to note that Mr. Black opened each door at most once, and in the end all doors became open.

Input

The first line contains integer nn (2n2000002≤n≤200000) — the number of doors.

The next line contains nn integers: the sequence in which Mr. Black opened the doors. The ii-th of these integers is equal to 00 in case the ii-th opened door is located in the left exit, and it is equal to 11 in case it is in the right exit.

It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit.

Output

Print the smallest integer kk such that after Mr. Black opened the first kk doors, he was able to exit the house.

Examples
Input
 
5
0 0 1 0 0
Output
 
3
Input
 
4
1 0 0 1
Output
3
Note

In the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.

When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.

In the second example when the first two doors were opened, there was open closed door in each of the exit.

With three doors opened Mr. Black was able to use the left exit.

 

 

解题思路:这道题就是给你n个数,0代表左边的门,1代表右边的门,只有把左边或者右边全部的门全部打开才可逃离,问最快逃离的序号;

实际上我们只需遍历一遍,看是先把左边的门遍历完还是右边的门遍历完即可,再输出答案;

 1 #include<iostream>
 2 #include<string.h>
 3 using namespace std;
 4 
 5 int n ;
 6 int a[200005];
 7 int olen = 0;         //0的个数,左边门的个数;
 8 int ylen = 0;         //1的个数,右边门的个数;
 9 int tmpo = 0;       //用来遍历统计左边的门的个数;
10 int tmpy = 0;      //用来遍历统计左边的门的个数;
11 int main()
12 {
13     cin>>n;
14     for(int i = 1 ; i <= n ; i++ )
15     {
16         cin>>a[i];
17         if(a[i]==1)
18         {
19             ylen++;
20         }else
21         olen++;
22     }
23     for(int i = 1 ; i <= n ; i++)
24     {
25         if(a[i]==1)
26         {
27             tmpy++;
28         }else
29         if(a[i]==0)
30         tmpo++;
31         
32         if(tmpy==ylen)  //用来遍历统计左边的门的个数;如果左边先遍历完则输出;
33         {
34             cout<<i;
35             break;
36         }else
37         if(tmpo==olen)   //右边同理;
38         {
39             cout<<i;
40             break;
41         }
42     }
43     return 0;
44 }

 

代码如下:

 

转载于:https://www.cnblogs.com/yewanting/p/10727214.html

内容概要:本文深入探讨了金属氢化物(MH)储氢系统在燃料电池汽车中的应用,通过建立吸收/释放氢气的动态模型和热交换模型,结合实验测试分析了不同反应条件下的性能表现。研究表明,低温环境有利于氢气吸收,高温则促进氢气释放;提高氢气流速和降低储氢材料体积分数能提升系统效率。论文还详细介绍了换热系统结构、动态性能数学模型、吸放氢特性仿真分析、热交换系统优化设计、系统控制策略优化以及工程验证与误差分析。此外,通过三维动态建模、换热结构对比分析、系统级性能优化等手段,进一步验证了金属氢化物储氢系统的关键性能特征,并提出了具体的优化设计方案。 适用人群:从事氢能技术研发的科研人员、工程师及相关领域的研究生。 使用场景及目标:①为储氢罐热管理设计提供理论依据;②推动车载储氢技术的发展;③为金属氢化物储氢系统的工程应用提供量化依据;④优化储氢系统的操作参数和结构设计。 其他说明:该研究不仅通过建模仿真全面验证了论文实验结论,还提出了具体的操作参数优化建议,如吸氢阶段维持25-30°C,氢气流速0.012g/s;放氢阶段快速升温至70-75°C,水速18-20g/min。同时,文章还强调了安全考虑,如最高工作压力限制在5bar以下,温度传感器冗余设计等。未来的研究方向包括多尺度建模、新型换热结构和智能控制等方面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值