⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 woods.cpp

📁 这是学校ACM程序设计大赛的题目,拿出来大家算是当练习
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
	int lenth;
	int weight;
}wnode;

void sort_w(wnode *w, int total)
{
	for(int i=0; i<total-1; i++)
	{
		for(int j=i+1; j<total; j++)
		{
			if(w[i].lenth>w[j].lenth/*||w[i].weight>w[j].weight*/)
			{
				wnode temp;
				temp=w[i];
				w[i]=w[j];
				w[j]=temp;
			}
			else
			{
				if(w[i].lenth==w[j].lenth&&w[i].weight>w[j].weight)
				{
					wnode temp;
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
				}
			}
		}
	}
	//已排序,等待在排序好的木堆中得到结果
	int count=0;
	for(int k=total-1; k>0; k--)
	{
		
		for(int s=k-1; s>=0; s--)
		{
			if(w[s].weight<=w[k].weight)
			{
				int temp;
				temp=w[s].weight;
				w[k].weight=temp;
				w[s].weight=65536;
			}
		}
	}
	for(int r=0; r<total; r++)
	{
		if(w[r].weight!=65536)
			count++;
	}
	printf("%d\n",count);
}
void main()
{
	FILE *fp;
	if((fp=fopen("woods.in","r"))==NULL)
	{
		printf("can't open file\n");
		exit(0);
	}
	int circle;
	fscanf(fp,"%d",&circle);
	if(circle>=1000)
		printf("不合题意\n");
	else
	{
		for(int s=0; s<circle; s++)
		{
			int total;
			fscanf(fp,"%d",&total);
			if(total<1||total>5000)
				printf("不合题意\n");
			else
			{
				wnode *w;
				w=(wnode *)malloc((total+5)*sizeof(struct node));
				for(int j=0; j<total; j++)
				{
					fscanf(fp,"%d",&((w+j)->lenth));
				    fscanf(fp,"%d",&((w+j)->weight));
				}
				sort_w(w,total);
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -