zoukankan      html  css  js  c++  java
  • UVA 11729

    UVA 11729

    大体是贪心做法,执行时间长的先交代

    训练指南原题解

    #include<cstdio>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    
    struct Job 
    {
    	int j, b;
    	bool operator < (const Job& x) const 
    	{
    		return j > x.j;
    	}
    };
    
    int main() 
    {
    	int n, b, j, kase = 1;
    	while(scanf("%d", &n) == 1 && n) 
    	{
    		vector<Job> v;
    		for(int i = 0; i < n; i++) 
    		{
    			scanf("%d%d", &b, &j); 
    			v.push_back((Job){j,b});
    		}
    		sort(v.begin(), v.end());
    
    		int s = 0;
    		int ans = 0;
    
    		for(int i = 0; i < n; i++)
    		{
    			s += v[i].b;
    			ans = max(ans, s+v[i].j);
    		}
    		printf("Case %d: %d
    ", kase++, ans);
    	}
    	return 0;
    }
    
    

    用cmp函数进行排序而非重载运算符

    #include<cstdio>
    #include<vector>
    #include<algorithm>
    
    using namespace std;
    
    struct Job 
    {
    	int j, b;
    	bool operator < (const Job& x) const 
    	{
    		return j > x.j;
    	}
    };
    
    int main() 
    {
    	int n, b, j, kase = 1;
    	while(scanf("%d", &n) == 1 && n) 
    	{
    		vector<Job> v;
    		for(int i = 0; i < n; i++) 
    		{
    			scanf("%d%d", &b, &j); 
    			v.push_back((Job){j,b});
    		}
    		sort(v.begin(), v.end());
    
    		int s = 0;
    		int ans = 0;
    
    		for(int i = 0; i < n; i++)
    		{
    			s += v[i].b;
    			ans = max(ans, s+v[i].j);
    		}
    		printf("Case %d: %d
    ", kase++, ans);
    	}
    	return 0;
    }
    
    
    透过泪水看到希望
  • 相关阅读:
    TextView 字数限制
    关于一个软件ipa包的其他图片资源
    查看一个软件ipa包的内容
    不断学习的博客
    高级iOS面试题
    CocoaPod出现-bash: pod: command not found 解决办法
    链表清空
    蛋疼的并查集
    再卖菜
    乒乓球男双输了
  • 原文地址:https://www.cnblogs.com/ronnielee/p/9495967.html
Copyright © 2011-2022 走看看