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


    luogu -P1253 线性存储问题

    贪心 贪速度,(f = v / t)

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    const int N = 10005;
    int n;
    struct node{
    	int f;
    	int id;
    };
    
    vector<node> v;
    
    bool cmp(node a,node b)
    {
    	return a.f > b.f;
    }
    int main()
    {
    	cin >> n;
    	int a, b ;
    	for(int i = 0;i < n ;i ++)
    	{
    		scanf("%d %d",&a ,&b);
    		v.push_back({a * b, i + 1});
    	}	
    	sort(v.begin(),v.end(),cmp);
    	for(int i = 0;i < v.size() ;i ++)
    	{
    		cout << v[i].id << " ";
    	}
    	return 0;
    } 
    

    luogu -P1324 矩形分割

    同样是贪心但是同时贪一次性切分的权重和切分次数乘机最小

    因为权值越大的越早切开之后会减少之后权值很大的被一直切分

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    const int N = 2005;
    int n , m;
    int col[N],row[N];
    
    bool cmp(int a,int b)
    {
    	return a > b;
    }
    int main()
    {
    	cin >> n >> m;
    	for(int i = 1;i < n ;i ++)
    	{
    		scanf("%d",&row[i]);
    	}
    	for(int i = 1;i < m ;i ++)
    	{
    		scanf("%d",&col[i]);
    	}
    	sort(row + 1,row + n , cmp);
    	sort(col + 1,col + m , cmp);
    	long long ans = 0;
    	int r = 1, c = 1;
    	for(int i = 2;i < n + m ;i ++)
    	{
    		if(row[r] > col[c])ans += c * row[r++];
    		else ans += r * col[c++];	
    	} 
    	cout << ans << endl;
    	return 0;
    } 
    

    luogu -P1294 高手散步

    裸的图的 dfs遍历(邻接矩阵)

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    const int N = 55;
    
    int map[N][N];
    int n , m;
    bool vis[N];
    
    int ans = -99999;
    
    void dfs(int now,int fav)
    {
    	ans = max(fav,ans);
    	for(int i = 1;i <= n ;i ++)
    	{
    		if(!vis[i] && map[now][i] > 0)
    		{
    			vis[i] = 1;
    			dfs(i,fav + map[now][i]);
    			vis[i] = 0;
    		}
    	}
    }
    int main()
    {
    	cin >> n >> m;
    	int a, b , c;
    	for(int i = 0;i < m ;i ++)
    	{
    		cin >> a >> b >> c;
    		map[a][b] = c;
    		map[b][a] = c;
    	}
    	
    	for(int i = 1;i <= n ;i ++)
    	{
    		vis[i] = 1;
    		dfs(i,0);
    		vis[i] = 0;
    		//fill(vis,vis + N, 0);
    	}
    	cout << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    全排列
    【React Native开发】React Native控件之DrawerLayoutAndroid抽屉导航切换组件解说(13)
    google PLDA + 实现原理及源代码分析
    codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
    关于系统运维监控的几点建议
    jquery插件jTemplates使用方法
    手动控制事务
    Android--数据库数据显示至屏幕
    Qt应用程序中设置字体
    读刘未鹏老大《你应当怎样学习C++(以及编程)》
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12512736.html
Copyright © 2011-2022 走看看