题意是处理一批木棍,如果当前处理的木棍长度和重量均大于前一根木棍的长度和重量,则处理当前木棍花费为 0,否则花费为 1。

用结构体存储木棍信息,将木棍按照长度从小到大排序,若长度相等则按照重量从小到大排序,在序列中找到比当前所处理的木棍长度和重量均大于且未处理的木棍再进行处理,若没有满足要求的木棍了,则再次从头开始处理未处理过的木棍,直到所有的木棍处理完毕。

代码如下:

 #include <bits/stdc++.h>
using namespace std;
struct stick
{
int l,w,num;
}p[];
bool cmp(stick a,stick b)
{
return a.l!=b.l?a.l<b.l:a.w<b.w;
}
int main()
{
int t,n,ans,sum,el,ew;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i = ; i < n; ++i)
{
scanf("%d%d",&p[i].l,&p[i].w);
p[i].num = ;
}
sort(p,p+n,cmp);
ans = sum = ;
while(sum<n)
{
el = ew = ;
for(int i = ; i < n; ++i)
if(p[i].num&&p[i].l>=el&&p[i].w>=ew)
{
p[i].num = ;
el = p[i].l;
ew = p[i].w;
++sum;
}
++ans;
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. 水的demo
  2. HTML5 Web app开发工具Kendo UI Web中如何绑定网格到远程数据
  3. Android 完整开源应用,完整开源项目
  4. Bootstrap插件系列——Bootstrap-table初始化、分页、客户端搜索、服务端搜索
  5. Maven Scope
  6. Java Hour 42 fastjson
  7. Linux platform设备简介
  8. 设计模式_Memento_备忘录模式
  9. wdlinux mysql innodb的安装
  10. Ubuntu知识记录
  11. POJ 3525 Most Distant Point from the Sea
  12. dump json 显示中文问题
  13. POJ - 2912 Rochambeau 种类并查集
  14. idea报错:Invalid bound statement (not found)
  15. /usr/bin/uwsgi --http :8888 --wsgi-file wsgi.py --master --processes 4 --threads 2
  16. kaggle-Digit Recognizer
  17. sql server: Graphs, Trees, Hierarchies and Recursive Queries
  18. hdu 1556 A - Color the ball 其他做法
  19. Delphi:窗体的扩展样式GWL_EXSTYLE用于SetWindowLong
  20. IDEA导入jar包

热门文章

  1. Java文件下载:如何编码文件名称以及如何设置HttpServletResponse
  2. Github如何提交修改的代码以及更新到最新版本
  3. SQLServer之UNIQUE约束
  4. jenkins使用开始踩坑(1)
  5. java.io.IOException: There appears to be a gap in the edit log. We expected txid ***, but got txid
  6. 搭建vue.js环境
  7. Asp.Net WebApi 使用OWIN架构后,出现 “没有 OWIN 身份验证管理器与此请求相关联(No OWIN authentication manager is associated with the request)” 异常的解决办法
  8. 基于HTML5 的互联网+地铁行业
  9. CI/CD持续集成/持续部署 敏捷开发
  10. jeecg字典表—普通表