213
At first I thought that as long as the length and weight ascending, and then find out when Length[i]!=length[i-1], weight[i]<weight[i-1] and then count++, the results found not so, 1 4 2 1 3 5 4 9 5 2 so that count is 3
In fact the order is 1 4 3 5 4 9 2 1 5 2 belongs to greedy strategy, as far as possible to make each processing of the stick more; This problem has a high demand for time, select Sort is not OK, select the fast row sort;
1#include <stdio.h>/*wa*/2typedefstruct 3 {4 intlength;5 intweight;6 }stick;7 intMain ()8 {9 intT;Tenscanf"%d",&t); One while(t--) A { - intN,i,j,count=0, first=1; -scanf"%d",&n); the stick a[n],t; - for(i=0; i<n;i++) -scanf"%d%d",&a[i].length,&a[i].weight); - for(i=0; i<n-1; i++) + for(j=i+1; j<n;j++) - { + if(a[i].length>a[j].length) A { att=A[i]; -a[i]=A[j]; -a[j]=T; - } - } - for(i=0; i<n-1; i++) in for(j=i+1; j<n;j++) - { to if((a[i].length==a[j].length) && (a[i].weight>a[j].weight)) + { -t=A[i]; thea[i]=A[j]; *a[j]=T; $ }Panax Notoginseng - } the for(i=0; i<n;i++) +printf"%d%d\n", a[i].length,a[i].weight); A for(i=1; i<n;i++) the { + if((a[i].length!=a[i-1].length) && (a[i].weight<a[i-1].weight)) -count++; $ } $ if(first==1) - { -printf"%d\n", count+1); thefirst=0; - }Wuyi Else theprintf"%d\n", count); - } Wu}
1#include <stdio.h>/*ac*/2#include <algorithm>3#include <string.h>/*the Memset function resets the array to memset (array name, replacement element, size)*///size is usually sizeof (array name) (all permutations), sizeof (int) *n4 using namespacestd;5typedefstruct 6 {7 intlength;8 intweight;9 }stick;Ten BOOLCMP (Stick X,stick y)/*Sort Sorting Method*/ One { A if(x.length<y.length) - return true; - if(x.length==y.length&&x.weight<y.weight) the return true; - return false; - } - intMain () + { - intT; +scanf"%d",&T); A while(t--) at { - intCount=0, i,j,n,t; -scanf"%d",&n); - stick a[n]; -Memset (A,0,sizeof(a)); - for(i=0; i<n;i++) inscanf"%d%d",&a[i].length,&a[i].weight); -Sort (a,a+n,cmp); to for(i=0; i<n;i++)/*The first stick is the time it takes to open a machine .*/ + { - if(a[i].weight!=0)/*greedy strategy, every time as much as possible to process the wooden stick!! */ the { *t=A[i].weight; $count++;Panax Notoginseng for(j=i+1; j<n;j++) - { the if(a[j].weight>=t) + { At=A[j].weight; thea[j].weight=0;/*post-machined stick quality 0*/ + } - } $ $ } - - } theprintf"%d\n", count); - }Wuyi}