C
来源:互联网 发布:java希尔排序算法 编辑:程序博客网 时间:2024/06/06 12:45
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
struct stick {
int len;
int wei;
}st[10000];
bool sure[5010];
int cmp(stick a, stick b)
{
if (a.len != b.len)
return a.len< b.len;
return b.wei > a.wei;
}
int main()
{
int n,t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int i, num = 0,time=0,j;
for (i = 0; i < n; i++)
scanf("%d %d", &st[i].len, &st[i].wei);
sort(st, st + n,cmp);
memset(sure, false, sizeof(sure));
for (i = 0; i < n; i++)
{
if (!sure[i])
{
sure[i] = true;
for (j = i + 1, time = st[i].wei; j < n; j++)
if (st[j].wei >= time && (!sure[j]))
{
time = st[j].wei;
sure[j] = true;
}
num++;
}
}
printf("%d\n",num);
}
return 0;
}
#include<stdlib.h>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
struct stick {
int len;
int wei;
}st[10000];
bool sure[5010];
int cmp(stick a, stick b)
{
if (a.len != b.len)
return a.len< b.len;
return b.wei > a.wei;
}
int main()
{
int n,t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
int i, num = 0,time=0,j;
for (i = 0; i < n; i++)
scanf("%d %d", &st[i].len, &st[i].wei);
sort(st, st + n,cmp);
memset(sure, false, sizeof(sure));
for (i = 0; i < n; i++)
{
if (!sure[i])
{
sure[i] = true;
for (j = i + 1, time = st[i].wei; j < n; j++)
if (st[j].wei >= time && (!sure[j]))
{
time = st[j].wei;
sure[j] = true;
}
num++;
}
}
printf("%d\n",num);
}
return 0;
}
阅读全文
0 0
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- 栈堆对于Activity的管理
- x=x|(x+1);和x=x&(x-1)?
- Java之LIst集合一
- HDU1871-1872-1873-结构体排序
- HDU 5407 CRB and Candies 数论
- C
- C语言之字符串
- 【项目管理和构建】——Maven简介(一)
- Button按钮圆角的设置:
- POJ1274: The Perfect Stall 题解
- hdu 2795 Billboard 线段树
- 如何用js给css3中的属性和jquery中的animate动态传值
- angular.js里的ng-show,ng-hide与ng-if的区别
- Machine Learning Notes II