心急的C小加
来源:互联网 发布:黄狮精 知乎 编辑:程序博客网 时间:2024/06/02 14:41
http://acm.nyist.net/JudgeOnline/problem.php?pid=236
心急的C小加
时间限制:1000 ms | 内存限制:65535 KB
难度:4
- 描述
C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?
- 输入
- 第一行是一个整数T(1<T<1500),表示输入数据一共有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
- 样例输出
213
/**AC之路,我选择坚持~~**//**二分**/#include <cstdio>#include <vector>#include <algorithm>#include <cstring>#include <queue>#include <cstring>#include <iostream>#define SI(T) int T;scanf("%d",&T)#define Max(x,y) x>y?x:yusing namespace std;const int SIZE=5e3+10;struct node{ int l; int w; bool operator<(const node &other)const{ return l<other.l||(l==other.l&&w<other.w); }}a[SIZE];int dp[SIZE];int b_s(int l,int r,int x){ while(l<r){ int m=l+(r-l)/2; if(dp[m]>x)l=m+1; else r=m; } return l;}int main(){ int n; SI(T); for(int cas=0;cas<T;cas++){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].l,&a[i].w); sort(a,a+n); memset(dp,0,sizeof(dp)); int ans=0; for(int i=0;i<n;i++){ int pos=b_s(0,n,a[i].w); if(ans==pos)dp[ans++]=a[i].w; else dp[pos]=a[i].w; } printf("%d\n",ans); } return 0;}
0 0
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的C小加
- 心急的c小加
- 心急的C小加
- Linux crontab 定时
- 设置JDeveloper工作空间
- 淘宝课程学习如何安排太原网络营销师强烈推荐
- 怎么理解Condition
- 使用Xcode7的Instruments检测解决iOS内存泄露
- 心急的C小加
- ORA-00392 ORA-00312 日志正在清除故障
- Jenkins学习总结(1)——Jenkins详细安装与构建部署使用教程
- LeetCode 206 Reverse Linked List
- larbin 的main函数
- block的使用
- 利用python库计算person相关系数
- HTML5 - 使用HTML5Forms让旧浏览器支持表单新特性,表单验证
- Android 事件分发