zoukankan      html  css  js  c++  java
  • 每日算法

    每日算法

    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.3.31


    P1802 5倍经验日

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    
    using namespace std;
    const int N = 1005;
    
    int n , x;
    struct node{
    	int l, w, c;
    	node(int l,int w,int c):l(l),w(w),c(c){}
    	node(){}
    };
    node p[N];
    int f[N][N];
    int main()
    {
    	cin >> n >> x;
    	for(int i = 1;i <= n ;i ++)
    	{
    		scanf("%d %d %d",&p[i].l,&p[i].w,&p[i].c);
    	}
    	
    	for(int i = 1;i <= n;i ++)
    	{
    		for(int j = 0;j <= x ;j ++)
    		{
    			if(j < p[i].c)
    			{
    				f[i][j] = f[i-1][j] + p[i].l;
    			}else{
    				f[i][j] = max(f[i-1][j] + p[i].l,f[i-1][j-p[i].c] + p[i].w);
    			}
    		}	
    	}
    	cout << (long long)f[n][x] * 5 << endl;
    	return 0;
    } 
    

    P1048 采药

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    
    using namespace std;
    const int N = 1010;
    int T , m;
    int w[N] , v[N] ; //花费时间
    int f[N][N];
    int main()
    {
    	cin >> T >> m;
    	for(int i = 1;i <= m ;i ++)
    	{
    		scanf("%d %d",&w[i],&v[i]);
    	}
    	for(int i = 1;i <= m ;i ++)
    	{
    		for(int j = 1;j <= T ;j ++)
    		{
    			if(j >= w[i])
    			{
    				f[i][j] = max(f[i-1][j],f[i-1][j - w[i]] + v[i]);
    			}else f[i][j] = f[i-1][j];
    		}
    	}
    	cout << f[m][T] << endl;
    	return  0;
    }
    

    一维

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    
    using namespace std;
    const int N = 1005;
    int t , m;
    int w[N], v[N], f[N];
    int main()
    {
    	cin >> t >> m;
    	for(int i = 1;i <= m; i++)
    	{
    		scanf("%d %d",&w[i],&v[i]);
    	}
    
    	for(int i = 1;i <= m ;i ++)
    	{
    		for(int j = t;j >= w[i] ;j --)
    		{
    			f[j] = max(f[j - w[i]] + v[i],f[j]);
    		}
    
    	}
    	cout << f[t] << endl;
    	return 0;
    }
    

    P1734 最大约数和

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    
    using namespace std;
    const int N = 1010;
    int s;
    int v[N];
    void func(int x)
    {
    	int ans = 0;
    	for(int i = 1;i < x;i ++)
    	{
    		if(x % i == 0)ans += i;
    	}
    	v[x] = ans;
    }
    int f[N][N];
    int main()
    {
    	cin >> s;
    	for(int i = 1;i <= s ;i ++)func(i);
    
    	for(int i = 1 ;i <= s; i++) //当前物品
    	{
    		for(int j = 1;j <= s;j ++) //当前容量
    		{
    			if(j >= i) // i 同时有代表其本身得权值 w[i]
    			{
    				f[i][j] = max(f[i-1][j],f[i-1][j-i] + v[i]);
    			}else f[i][j] = f[i-1][j];
    		}
    	}
    	cout << f[s][s] << endl;	
    	return 0;
    }
    

    一维优化

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    
    using namespace std;
    const int N = 1010;
    int s;
    int v[N];
    void func(int x)
    {
    	int ans = 0;
    	for(int i = 1;i < x;i ++)
    	{
    		if(x % i == 0)ans += i;
    	}
    	v[x] = ans;
    }
    int f[N];
    int main()
    {
    	cin >> s;
    	for(int i = 1;i <= s ;i ++)func(i);
    
    	for(int i = 1 ;i <= s; i++) //当前物品
    	{
    		for(int j = s;j >= i;j --) //当前容量
    		{        // i 同时有代表其本身得权值 w[i]
    			f[j] = max(f[j],f[j-i] + v[i]);
    		}
    	}
    	cout << f[s] << endl;	
    	return 0;
    }
    
  • 相关阅读:
    MySQL ==> Maxwell ==> Kafka ==> Spark
    HBase 基本操作
    Spark Streaming 整合Kafka的 Offset 管理 【数据零丢失之 checkpoint 方式管理Offset】
    数据零丢失 + 仅一次消费数据【终极方案】
    Spark大数据相关经典面试题总结 【一直更新...】
    Spark Streaming 整合Kafka的 Offset 管理 【数据零丢失之 MySQL管理Offset】
    InfuxDB 时序数据库入门+influxdb-java
    Connection to node 0 could not be established. Broker may not be available.
    天池新人实战赛之[离线赛]-初体验-Spark处理
    Java进阶【有空常翻出来看看】
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12609688.html
Copyright © 2011-2022 走看看