标签:blog http io ar os sp for 数据 div
C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?
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<iostream> #include<cstdio> #include<cstring> #include<string> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; int n,t,cnt; struct line { int x,y; }e[5010]; bool cmp(line a,line b) { if(a.x!=b.x) return a.x<b.x; return a.y<b.y; } int main() { scanf("%d",&t); for(int i=1;i<=t;i++) { cnt=0; memset(e,0,sizeof(e)); scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&e[i].x,&e[i].y); sort(e,e+n,cmp); for(int i=0;i<n;i++) { if(e[i].y!=0) { int t=e[i].y; cnt++; for(int j=i+1;j<n;j++) { if(e[j].y>=t) { t=e[j].y; e[j].y=0; } } } } printf("%d\n",cnt); } return 0; }
标签:blog http io ar os sp for 数据 div
原文地址:http://www.cnblogs.com/a972290869/p/4099960.html