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

📄 1869624_ac_0ms_64k.c

📁 北大大牛代码 1240道题的原代码 超级权威
💻 C
字号:
# include <stdio.h>
# include <stdlib.h>

struct node
{
 int L;
 int W;
}stick[5001];

int cmp(const void *a, const void *b)
{
  struct node *aa = (struct node *)a;    
  struct node *bb = (struct node *)b;    
  if(aa->L != bb->L)
    return aa->L - bb->L;
  else 
    return aa->W - bb->W;
}

int main()
{
 int n, T, i, j;
 int t2, no;
 
 scanf("%d",&T);
 while(T--)
 {
  scanf("%d",&n);
  for(i = 0; i < n; i++)
   scanf("%d%d",&stick[i].W,&stick[i].L);
   qsort(stick,n,sizeof(stick[0]),cmp);
   no = 0;
   for(i = 0; i < n; i++)
    {
     if(!stick[i].L) continue;
     no++;
      t2 = stick[i].W;
      for(j = i; j < n; j++)
       if(stick[j].W >= t2)
        {
         stick[j].L = 0;
         t2 = stick[j].W;
         stick[j].W = 0;
        } 
    }
    printf("%d\n",no);
 }
}

⌨️ 快捷键说明

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