zoukankan      html  css  js  c++  java
  • HDOJ 5188 zhx and contest 贪婪+01背包



    zhx and contest

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 455    Accepted Submission(s): 158


    Problem Description
    As one of the most powerful brushes in the world, zhx usually takes part in all kinds of contests.
    One day, zhx takes part in an contest. He found the contest very easy for him.
    There are n problems in the contest. He knows that he can solve the ith problem in ti units of time and he can get vi points.
    As he is too powerful, the administrator is watching him. If he finishes the ith problem before time li, he will be considered to cheat.
    zhx doesn't really want to solve all these boring problems. He only wants to get no less than w points. You are supposed to tell him the minimal time he needs to spend while not being considered to cheat, or he is not able to get enough points. 
    Note that zhx can solve only one problem at the same time. And if he starts, he would keep working on it until it is solved. And then he submits his code in no time.
     

    Input
    Multiply test cases(less than 50). Seek EOF as the end of the file.
    For each test, there are two integers n and w separated by a space. (1n300w109)
    Then come n lines which contain three integers ti,vi,li. (1ti,li105,1vi109)
     

    Output
    For each test case, output a single line indicating the answer. If zhx is able to get enough points, output the minimal time it takes. Otherwise, output a single line saying "zhx is naive!" (Do not output quotation marks).
     

    Sample Input
    1 3 1 4 7 3 6 4 1 8 6 8 10 1 5 2 2 7 10 4 1 10 2 3
     

    Sample Output
    7 8 zhx is naive!
     

    Source
     



    /* ***********************************************
    Author        :CKboss
    Created Time  :2015年03月19日 星期四 10时26分15秒
    File Name     :HDOJ5188.cpp
    ************************************************ */
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <cmath>
    #include <cstdlib>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    
    using namespace std;
    
    const int maxn=200100;
    
    int n,w;
    int sumtime,sumv;
    int dp[maxn*30];
    
    struct PB
    {
    	int t,v,l;
    }pb[50];
    
    bool cmp(PB a,PB b)
    {
    	return a.l-a.t<b.l-b.t;
    }
    
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    
    	while(scanf("%d%d",&n,&w)!=EOF)
    	{
    		sumv=0;
    		for(int i=0;i<n;i++)
    		{
    			int x,y,z;
    			scanf("%d%d%d",&x,&y,&z);
    			pb[i]=(PB){x,y,z};
    			sumv+=y;
    		}
    		if(sumv<w)
    		{
    			puts("zhx is naive!");
    			continue;
    		}
    
    		sort(pb,pb+n,cmp);
    		memset(dp,0,sizeof(dp));
    		for(int i=0;i<n;i++)
    			for(int j=maxn;j>=max(pb[i].t,pb[i].l);j--)
    				dp[j]=max(dp[j],dp[j-pb[i].t]+pb[i].v);
    
    		int ans=0;
    		for(int i=0;i<maxn;i++)
    			if(dp[i]>=w) { ans=i; break; }
    
    		printf("%d
    ",ans);
    	}
        
        return 0;
    }
    




    版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

  • 相关阅读:
    swagger序列化对example属性的特殊处理造成的json格式异常问题
    Elasticsearch 6.2.4 xpack白金版破解-仅供交流学习使用
    Logback多进程写入同一日志文件时滚动日期混乱问题
    mycat事务中上来执行select马上提交——小猫如此折腾,我选dble
    我家很管事的猫——mycat初步部署实践与问题排查
    certbot https签发证书与自动更新——acme实在太难用,certbot一键式全搞定
    自力更生Collections.sort发现比较结果混乱?Comparator的锅还是强转类型导致?
    Java SPI、servlet3.0与@HandlesTypes源码分析
    真——Springcloud支持Https
    Controller层的方法访问标志与Spring装配与AspectJ切面处理
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4745470.html
Copyright © 2011-2022 走看看