#35759: Ans


yp11151230@yphs.tp.edu.tw (710-43蔡亞儒)

學校 : 臺北市私立延平高級中學
編號 : 197211
來源 : [203.72.178.1]
最後登入時間 :
2023-06-14 17:43:23
f820. 極限運動 (Sports) -- TOI練習賽202104新手組第3題 | From: [203.72.178.1] | 發表日期 : 2023-06-15 17:08

#include<stdio.h>

int main()
{
	int a=0;
	scanf("%d",&a);
	int height[500]={};
	for(int i=1;i<=a;++i)
	{
		scanf("%d",&height[i]);
	}
	int drop_point=0;
	scanf("%d",&drop_point);
	int l_min=-777,r_min=-777,l_index=-1,r_index=-1;
	int l_temp=drop_point,r_temp=drop_point;
	while(height[r_temp]>=height[r_temp+1]&&r_temp+1<a+1)
	{
		r_min = height[r_temp];
		if(r_min >= height[r_temp+1])
		{
			r_min=height[r_temp+1];
			r_index=r_temp+1;
		}
		r_temp+=1;
	}
	if(r_min<0)
	{
		r_min=5000000;
	}
	while(height[l_temp]>=height[l_temp-1]&&l_temp-1>0)
	{
		l_min = height[l_temp]; 
		if(l_min >= height[l_temp-1])
		{
			l_min=height[l_temp-1];
			l_index=l_temp-1;
		}
		l_temp-=1;
	}
	if(l_min<0)
	{
		l_min=5000000;
	}
	if(r_min<l_min)
	{
		printf("%d\n",r_index);
	}
	else if (r_min>l_min)
	{
		printf("%d\n",l_index);
	}
}
 
#35761: Re: Ans


yp11151230@yphs.tp.edu.tw (710-43蔡亞儒)

學校 : 臺北市私立延平高級中學
編號 : 197211
來源 : [203.72.178.1]
最後登入時間 :
2023-06-14 17:43:23
f820. 極限運動 (Sports) -- TOI練習賽202104新手組第3題 | From: [203.72.178.1] | 發表日期 : 2023-06-15 17:30

#include <stdio.h>

int main() {
  int a = 0;
  scanf("%d", &a);
  int height[500] = {};
  for (int i = 1; i <= a; ++i) {
    scanf("%d", &height[i]);
  }
  int drop_point = 0;
  scanf("%d", &drop_point);
  int l_min = -777, r_min = -777, l_index = -1, r_index = -1;
  int l_temp = drop_point, r_temp = drop_point;
  while (height[r_temp] >= height[r_temp + 1] && r_temp + 1 < a + 1) {
    r_min = height[r_temp];
    if (r_min >= height[r_temp + 1]) {
      r_min = height[r_temp + 1];
      r_index = r_temp + 1;
    }
    r_temp += 1;
  }
  if (r_min < 0) {
    r_min = 5000000;
  }
  while (height[l_temp] >= height[l_temp - 1] && l_temp - 1 > 0) {
    l_min = height[l_temp];
    if (l_min >= height[l_temp - 1]) {
      l_min = height[l_temp - 1];
      l_index = l_temp - 1;
    }
    l_temp -= 1;
  }
  if (l_min < 0) {
    l_min = 5000000;
  }
  if (r_min < l_min) {
    printf("%d\n", r_index);
  } else if (r_min > l_min) {
    printf("%d\n", l_index);
  }
}

 
ZeroJudge Forum