poj 1065 Wooden Sticks

2014-11-24 00:12:12 · 作者: · 浏览: 4

思想很容易想到,证明是看了别的解题报告:利用到偏序定理:贪心算法实现


  #include    



#include    
using namespace std;  
/*328K  16MS*/  
typedef struct _pair  
{  
        int l;  
        int w;  
}Pair;  
  
int cmp(const void *a,const void *b)  
{  
    Pair a1=*(Pair *)a;  
    Pair b1=*(Pair *)b;  
    if(a1.l==b1.l)  
       return a1.w-b1.w;  
    return a1.l-b1.l;  
}  
  
int main()  
{  
    int t;  
    cin>>t;  
    while(t--)  
    {  
        int n;  
        cin>>n;  
        Pair *p=new Pair[n];  
        bool *b=new bool[n];  
        memset(b,false,sizeof(bool)*n);  
  
        for(int i=0;i>p[i].l>>p[i].w;  
        //计算反链   
        qsort(p,n,sizeof(p[0]),cmp);  
        int count=0;   
        for(int i=0;i=p[k].w&&!b[j])  
                      {  
                                 b[j]=true;  
                                 k=j;  
                      }      
                }  
                b[i]=true;  
        }  
          
        cout<
#include using namespace std; /*328K 16MS*/ typedef struct _pair { int l; int w; }Pair; int cmp(const void *a,const void *b) { Pair a1=*(Pair *)a; Pair b1=*(Pair *)b; if(a1.l==b1.l) return a1.w-b1.w; return a1.l-b1.l; } int main() { int t; cin>>t; while(t--) { int n; cin>>n; Pair *p=new Pair[n]; bool *b=new bool[n]; memset(b,false,sizeof(bool)*n); for(int i=0;i>p[i].l>>p[i].w; //计算反链 qsort(p,n,sizeof(p[0]),cmp); int count=0; for(int i=0;i=p[k].w&&!b[j]) { b[j]=true; k=j; } } b[i]=true; } cout<