problem 1025

很久以前写的,到现在才改对了--||。先排下序然后再一次次找,效率很一般!

Accepted1025C++00:00.03492K

#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#define swap(x,y) if(x != y) {x = x^y; y = y^x; x = x^y;}
struct s { int l, w; bool  b; };
void sort(struct s a[],int p,int
 r)
{
    
for(int i = p - 1; p < r; i = p - 1
)
    {
        
for(int j = p; j < r; j++
)
            
if((a[j].l < a[r].l) || (a[j].l == a[r].l && a[j].w <
 a[r].w))
            {
                i
++
;
                swap(a[i].l,a[j].l);
                swap(a[i].w,a[j].w);
            }
        i
++
;
        swap(a[i].l,a[r].l);
        swap(a[i].w,a[r].w);
        sort(a,p,i 
- 1
);
        p 
= i + 1
;
    }
}
void
 solve()
{
    
int
 n;
    scanf(
"%d",&
n);
    
struct s *stick = (struct s*)malloc(n * sizeof(struct
 s));
    memset(stick, 
0sizeof(stick[0]) *
 n);
    
int i, cnt = 0, res = 0
;
    
for(i = 0; i < n; i++
)
        scanf(
"%d%d"&stick[i].l, &
stick[i].w);
    sort(stick, 
0, n - 1
);
    
for(int temp = -1; cnt < n; ++res, temp = -1
)
        
for(i = 0; i < n; i++
)
            
if(!stick[i].b && stick[i].w >=
 temp)
                temp 
= stick[i].w, stick[i].b = true, cnt++
;
    free(stick);
    printf(
"%d/n"
,res);
}
int
 main()
{
#ifndef ONLINE_JUDGE
    freopen(
"1025.txt","r"
,stdin);
#endif

    
int  t;
    
while(scanf("%d"&t) !=
 EOF)
        
while(t--
)    solve();
#ifndef ONLINE_JUDGE
    fclose(stdin);
#endif

    
return 0 ;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值