南阳oj 236 心急的C小加
来源:互联网 发布:做美工的工资一般多少 编辑:程序博客网 时间:2024/05/22 05:08
心急的C小加
时间限制:1000 ms | 内存限制:65535 KB
难度:4
描述
C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?
输入
第一行是一个整数T,表示输入数据一共有T组。
每组测试数据的第一行是一个整数N(1<=N<=5000),表示有N个木棒。接下来的一行分别输入N个木棒的L,W(0 < L ,W <= 10000),用一个空格隔开,分别表示木棒的长度和质量。
输出
处理这些木棒的最短时间。
样例输入
3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1
样例输出
2
1
3
这个题一开始的时候是用最长递增子序列做的,但是超时了
思路:
结构体排序,接下来很简单了可以看看
#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>#include<math.h>#include<stdlib.h>#include<stack>#include<vector>#include<string.h>#include<map>#define INF 0x3f3f3f3f3fusing namespace std;struct node{ int x; int y;} a[5005];int cmp(node aa,node bb){ return (aa.x==bb.x?aa.y<bb.y:aa.x<bb.x);}int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d%d",&a[i].x,&a[i].y); sort(a,a+n,cmp); int max=-1; for(int i=0; i<n; i++) { if(a[i].y==0) continue; else { max=a[i].y; for(int j=i+1; j<n; j++) { if(a[j].y>=max) { max=a[j].y; a[j].y=0; } } } } int ans=0; for(int i=0; i<n; i++) if(a[i].y) ans++; printf("%d\n",ans); }}
1 0
- 南阳oj 236 心急的C小加
- 南阳oj 动态规划 心急的c小加 题目236
- 心急的C小加-OJ
- 心急的C小加(南阳oj236)(贪心)
- 南阳理工OJ_题目236 心急的C小加&&ZOJ_1025 Wooden Sticks
- NYOJ 236 心急的C小加
- nyoj 236 心急的C小加
- NYOJ-236:心急的C小加
- 南工236 心急的C小加
- NYOJ 236心急的C小加
- nyoj 236 心急的c小加
- nyoj-236-心急的C小加
- 【NYOJ 236 心急的C小加】
- NYOJ 236 心急的C小加
- NYOJ 236 心急的C小加
- 236 心急的C小加
- NYOJ 236 心急的C小加
- NYOJ 236 心急的C小加
- 大数的加法
- InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("dbconfig.properties")的作用
- memcacheq 的安装和使用
- python3字符串编码总结-str bytes
- ElasticSearch配置详解
- 南阳oj 236 心急的C小加
- 并查集&拓扑排序 (hdu1811)
- [codevs1020] 孪生蜘蛛
- Android的Parcelable接口
- About word
- POJ 1833 排列(水)
- Oracle学习总结(5)—— SQL语句经典案例
- 设置OnEditorActionListener后监听不到ACTION_SEARCH问题
- LeetCode 120. Triangle