Buying A House

本文提供了一种解决VJudge竞赛中C题的有效方法。通过使用数组标记房间占用情况,并进行线性扫描确定最近的空闲房间,实现了快速查找。代码采用C语言编写,适用于算法竞赛及初学者学习。

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

题目链接:https://vjudge.net/contest/162220#problem/C

题解:

1.利用数组标记是否有人入住

2.以二丫为中心,分两次线性扫描得出前后两个最短距离

3.两个比较得出min

AC code:

#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
 int n,m,k;
 int a[110];
 int sta[110];
 scanf("%d%d%d",&n,&m,&k);
  memset(sta,0,sizeof(sta));
  for(int i=1;i<=n;i++)
  {
   scanf("%d",&a[i]);
   if(a[i]==0)
   {
    sta[i]=1;
   }
  }
  int mark,mark1;
  for(int i=m;i>=1;i--)
  {
   if(sta[i]==0 && a[i]<=k)
   {
    mark=i;
    break;
   }
  }
  mark=abs(mark-m)*10;
  for(int i=m;i<=n;i++)
  {
   if(sta[i]==0 && a[i]<=k)
   {
    mark1=i;
    break;
   }
  }
  mark1=abs(mark1-m)*10;
  if(mark1<=mark)
  {
   printf("%d\n",mark1);
  }
  else
  {
   printf("%d\n",mark);
  }
 
 return 0;
}

转载于:https://www.cnblogs.com/DemonZiv/p/6818848.html

帮我看看这段话有没有语法错误:The first effect of guaranteeing people have basic financial products and services is increasing the overall quality of people’s lives. Ensuring reliable access to financial products and services can contribute to helping families and companies plan the future from two aspects, long-term goals and unexpected emergencies (The World Bank, 2022). Long-term goals mean long-term investments such as investments in health: saving money against illness, saving for a child’s education, saving for a house or car, etc. Unexpected emergencies mean managing risk, that is, people can apply for a loan from the bank when they are in the face of a sudden bankruptcy or business shock. Furthermore, when people meet weather financial shocks, the government and banks will give some financial assistance. With these financial services, people have a basic guarantee of life and a clear plan for the future in the meanwhile. Guarantee of financial services leads them to save a sum of money in a safe bank account for buying a house, providing funds for children’s education, and buying medical insurance for both themselves and their families to prevent the sudden arrival of diseases. In daily life, online payment improves life efficiency such as reducing queuing time. Additionally, in occupational life, financial guarantees can encourage and empower young people can be bolder to pursue their entrepreneurial dreams by providing them with start-up funds from banks. All in all, the guarantee of financial products leads to individuals plan for their financial futures and improve their overall quality of life.
05-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值