当前位置:网站首页>Past blue bridge cup test questions ants catch cold
Past blue bridge cup test questions ants catch cold
2022-06-28 19:49:00 【Yuyy】
This paper is finally updated at 1174 Days ago, , The information may have developed or changed .
Problem description
Long 100 Cm long and thin straight pole n Only ants . Some of their heads are to the left , Some of them face right. .
Every ant can only climb along the pole , The velocity is 1 centimeter / second .
When two ants meet , They will turn around and crawl in the opposite direction at the same time .
Among these ants , Yes 1 Only ants have a cold . And when we meet other ants , Can spread cold to ants .
Please calculate , When all the ants get off the pole , How many ants have a cold .
Input format
Enter an integer in the first line n (1 < n < 50), Represents the total number of ants .
The next line is n Integers separated by spaces Xi (-100 < Xi < 100), Xi The absolute value of , Represents the distance of the ant from the left end of the pole . A positive value means head right , Negative means head left , Not in data 0 value , And there will be no two ants occupying the same place . among , The first data represents that the ant has a cold .
Output format
Request output 1 It's an integer , Indicates the number of last cold ants . The sample input 3 5 -2 8 Sample output 1 The sample input 5 -10 8 -20 12 25 Sample output 3
Tips
When two ants meet , They will turn around and crawl in the opposite direction at the same time . It can be understood as crossing the shoulder , The effect is the same .
Code
using namespace std;
int main(){
int array[55];
int n,flag,flag1=0,flag2=0,temp,sum=1;
cin>>n;
cin>>flag;
for(int i=1;i<n;i++){
cin>>array[i];
//cin>>temp;
//array[i]=temp;
}
if(flag>0){
for(int i=1;i<n;i++){
if(array[i]<0&&(flag+array[i])<0){
sum++;
flag1=1;
}
}
if(flag1==1){
for(int i=1;i<n;i++){
if(array[i]>0&&(flag-array[i])>0){
sum++;
}
}
}
}
else{
for(int i=1;i<n;i++){
if(array[i]>0&&(flag+array[i])<0){
sum++;
flag2=1;
}
}
if(flag2==1){
for(int i=1;i<n;i++){
if(array[i]<0&&(flag-array[i])>0){
sum++;
}
}
}
}
cout<<sum;
return 0;
}Post Views: 266
边栏推荐
猜你喜欢

论文笔记:Universal Value Function Approximators

数据基础设施升级窗口下,AI 新引擎的技术方法论

H5 sunflower operation

How to obtain the coordinates of the aircraft passing through both ends of the radar

Analysys analytics' 2022 China Banking privacy computing platform supplier strength matrix analysis' research activity was officially launched

《数据安全法》出台一周年,看哪四大变化来袭?

令人惊艳的NanoPC-T4(RK3399)作为工作站的初始配置和相关应用

如何获取飞机穿过雷达两端的坐标

In which industries did the fire virtual human start to make efforts?

Bayesian inference problem, MCMC and variational inference
随机推荐
Demo of intelligent computing system 2 bangc operator development (heterogeneous programming flow of CPU and mlu270)
100人成绩的平均
Analysys analytics' 2022 China Banking privacy computing platform supplier strength matrix analysis' research activity was officially launched
kettle(六):基于Kettle的数据库全量备份
Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature
JSP to get the value in the session
【算法篇】刷了两道大厂面试题,含泪 ”重学数组“
Autumn recruitment experience sharing | how to prepare for bank interview
2837. The total number of teams
The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
Upward and downward transformation
从设计交付到开发,轻松畅快高效率!
5g NR MBS architecture introduction
论文笔记:Universal Value Function Approximators
Win11如何给系统盘瘦身?Win11系统盘瘦身方法
MDM data analysis function description
Parallax JS special effect JS carousel map plug-in
2022年4月10日--使用C#迈出第一步--使用C#从.NET类库调用方法(没看懂)
Gaozelong, a digital economy expert: Yingke changed its name to yingcosmos. Will yuancosmos become the next growth engine of Yingke?
Rigid error: could not extract PIDs from PS output PIDS: [], Procs: [“bad pid