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();
    	}
    }
    
  • 相关阅读:
    【初码干货】使用阿里云开放搜索服务快速搭建资源搜索网站
    很认真的聊一聊程序员的自我修养
    【初码干货】使用阿里云邮件推送服务架设自己邮件验证与推送体系
    Supervisor 修改配置文件中的参数值,需要更新服务才能生效
    如何关闭 IntelliJ IDEA 的 Find in Path ?
    Jenkins 服务启动/关闭/重启命令,设置端口
    java.util.ConcurrentModificationException 问题处理
    MySQL 将字符串类型的小数转换为保留位数的小数类型
    Apache Tomcat 文件包含漏洞(CVE-2020-1938)
    Error EElFTPSError: Data channel transfer error (error code is 10054) MobaXterm
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12764693.html
Copyright © 2011-2022 走看看