大佬求助,为什么开动态数组占的空间反而更大??
  • 板块P1161 开灯
  • 楼主Hayzeros
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/7/23 19:57
  • 上次更新2023/11/4 13:32:01
查看原帖
大佬求助,为什么开动态数组占的空间反而更大??
130819
Hayzeros楼主2021/7/23 19:57
#include <cstdio>
using namespace std;
struct node
{
	int l;
	bool f=0;
	node *next=NULL;
}*h,*r,*p;
int main()
{
	int n;
	scanf("%d",&n);
	h=new node;
	r=h; h->l=0;
	for (int i=1; i<=n; i++)
	{
		double a; int t;
		scanf("%lf%d",&a,&t);
		if ((h->l)<int(a*t))
		{
			for (int j=(h->l)+1; j<=int(a*t); j++)
			{
				(h->l)++;
				p=new node;
				p->l=j;
				r->next=p;
				r=p;
			}
		}
		p=h->next;
		for (int j=1; j<=t; j++)
		{
				int s=int(a*j);
				while((p->l)<s) p=p->next;
				p->f=!(p->f);
		}
	}
	p=h->next;
	while(1)
	{
		if ((p->f)==1)
		{
			printf("%d",p->l);
			return 0;
		}
		else p=p->next;
	}
}
2021/7/23 19:57
加载中...