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();
    	}
    }
    
  • 相关阅读:
    JS中原型链的理解
    CSS3的笔记总结
    那些牛掰的 HTML5的API(二)
    初识 HTML5(一)
    jQuery基础知识点(下)
    jQuery基础知识点(DOM操作)
    jQuery基础知识点(上)
    [译]GC专家系列2:Java 垃圾回收的监控
    [译]GC专家系列1: 理解Java垃圾回收
    [译]深入理解JVM
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12764693.html
Copyright © 2011-2022 走看看