zoukankan      html  css  js  c++  java
  • Daliy Algorithm (数学,推理,贪心)-- day 64

    Nothing to fear

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.4.23


    Middle Class

    贪心问题:

    思路一:

    1. 给序列进行从小到大得排序
    2. 从最大得那个人开始每次将它多余得财富转移给下一个人
    3. 观察下一个人本身得得财富+转移得财富是否能满足富人条件
    4. 将剩下得在进行转移给下一个人
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    
    void slove()
    {
    	int n , w;
    	cin >> n >> w;
    	vector<int> a(n);
    	for(int i = 0;i < n ;i ++)cin >> a[i];
    
    	sort(a.begin(), a.end());
    	ll ans = 0, s = 0;
    	for(int i = n - 1;i >= 0 ;i--)
    	{
    		if(s + a[i] - w >= 0)
    		{
    			s += a[i] - w;
    			ans++;
    		}else break;
    	}
    	cout << ans << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    level statistics

    数学+ 模拟 注意边界

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    #define x first
    #define y second
    
    using namespace std;
    typedef long long ll;
    const int N = 105;
    const int MAX = 0x7ffffff;
    int t;
    pair<int,int> arr[N];
    void slove()
    {
    	int n ;
    	cin >> n ;
    	for(int i = 0;i < n ;i ++)
    	{
    		cin >> arr[i].x >> arr[i].y;
    	}
    	bool f = false;
    	int p = 0, c = 0;
    	for(int i = 0;i < n ;i ++)
    	{	
    		int pi = arr[i].x - p,ci = arr[i].y - c; 
    		if(pi < 0 || ci < 0 || ci > pi){
    			f = 1;break;
    		}
    		p = arr[i].x,c = arr[i].y;
    	}
    	if(f)cout << "NO" << endl;
    	else cout << "YES" << endl;
     }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    
  • 相关阅读:
    激活函数
    第五章 Odoo 12开发之导入、导出以及模块数据
    第四章 Odoo 12 开发之模块继承
    第三章 Odoo 12 开发之创建第一个 Odoo 应用
    第二章 Odoo 12开发之开发环境准备
    第一章 使用开发者模式快速入门 Odoo 12
    【linux之路】常用的命令
    【python之路46】内置函数2,是【python之路18】的补充
    【python之路45】tornado的用法 (三)
    【python之路44】tornado的用法 (二)
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12764693.html
Copyright © 2011-2022 走看看