acbdcjt 2021-05-19 14:23 采纳率: 50%
浏览 32

Play Snuke 运行时间过长

Takahashi wants to buy the popular video game console called Play Snuke.
There are \(N\) shops that sell Play Snuke: Shop \(1, 2, \dots, N\). Shop \(i\) is \(A_i\) minutes' walk from where Takahashi is now, sells Play Snuke for \(P_i\) yen (Japanese currency), and currently has \(X_i\) Play Snukes in stock.
Now, Takahashi will go to one of those shops on foot and buy Play Snuke if it is still in stock when he gets there.
However, Play Snuke is so popular that the number of consoles in stock (if any) in every shop will decrease by \(1\) at the following moments: \(0.5, 1.5, 2.5, \dots\) minutes from now.
Determine whether Takahashi can buy Play Snuke. If he can, find the minimum amount of money needed to buy one.

 

#include<stdio.h>
#include<stdlib.h>
int main()
{
    struct shop{
    int s;
    int w;
    int n;
    }*ps;
    int a,i,x=0,j=0,*p,m;
    scanf("%d",&a);
    p=(int*)malloc(a*sizeof(int));
    ps=(struct shop*)malloc(a*sizeof(struct shop));
    for(i=0;i<a;i++)
    {scanf("%d%d%d",(ps+i)->s,(ps+i)->w,(ps+i)->n);}
    for(i=0;i<a;i++)
    {
        if((ps+i)->s<(ps+i)->n)
        {x++;}
        else{
            *(p+j)=(ps+i)->w;
            j++;
            }
    }free(ps);
    if(x==a)
    {printf("-1");}
    else
    {m=*p;
    for(i=0;i<j;i++)
        {
        if(m<*(p+i))
            m=*(p+i);
        }
        printf("%d",m);
    }free(p);
}

  • 写回答

1条回答 默认 最新

  • 爱编程的小芒果 2023-07-17 12:47
    关注

    建议你看看这篇博客,能先点个采纳吗,谢谢!
    博客网址:(https://blog.csdn.net/acbdcjt/article/details/117122753)

    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度