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


    luogu -P1376 机器工厂

    贪心问题注意策略得转化 别要死于固定得暴力形式,虽然是贪心思想实现起来也有很多得技巧

    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <cstdio>
    
    using namespace std;
    int n , s , c , y;
    
    int main()
    {
    	cin >> n >> s;
    	int a, b ,ans = 0;
    	long long  sum = 0;
    	cin >> a >> b;
    	ans = a;
    	sum += ans * b;
    	//如果留有剩余就相当于在基础价格上加上s 和当前取min 
    	for(int i = 1;i < n ;i ++)
    	{
    		scanf("%d %d",&a, &b);
    		ans = min(ans + s,a);  
    		sum += ans * b;
    	}
    	cout << sum << endl;
    	return 0;
    } 
    

    luogu -P1219 [USACO1.5]八皇后 Checker Challenge

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    const int N = 110;
    
    int n; 
    int A[N] , B[N] , C[N] , D[N];
    int cnt = 0;
    
    bool check(int i,int j)
    {
    	if((!B[j]) && (!C[i+j]) && (!D[i-j+n]))return 1;
    	else return 0;
    }
    void turnup(int i,int j)
    {
    	A[i] = j;B[j] = 1;C[i+j] = 1;D[i-j+n] = 1;
    }
    void turndown(int i,int j)
    {
    	B[j] = 0;C[i+j] = 0;D[i-j+n] = 0;
    }
    
    void print()
    {
    	for(int i = 1;i <= n;i ++)cout << A[i] << " ";
    	cout << endl;
    }
    void dfs(int now)
    {
    	if(now > n)
    	{
    		if(cnt < 3)print();
    		cnt++;
    	}
    	for(int i = 1;i <= n;i ++)
    	{
    		if(check(now,i)) 
    		{
    			turnup(now,i);
    			dfs(now + 1);
    			turndown(now,i);						
    		}
    	}
    } 
    int main()
    {
    	cin >> n;
    	dfs(1);	
    	cout << cnt;
    	return 0;
    }
    

    luogu- P1130 红牌 (dp)

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    const int N = 2005;
    int a[N][N],  f[N][N], n , m;
    int main()
    {
    	cin >> n >> m;
    	
    	for(int i = 1;i <= m ;i ++)
    	{
    		for(int j = 1;j <= n ;j ++)
    		{
    			scanf("%d",&a[j][i]);
    		}
    	}
    	
    	for(int i = 1;i <= n ;i ++)
    	{
    		f[i-1][0] = f[i-1][m];
    		for(int j = 1;j <= m ;j ++)
    		{
    			f[i][j] = min(f[i-1][j-1],f[i-1][j]) + a[i][j];
    		}
    	}
    	
    	int ans = f[n][1];
    	for(int i = 2;i <= m ;i ++)
    	{
    		ans = min(ans,f[n][i]);
    	}
    	cout << ans << endl;
    	return 0;
    } 
    

    luogu- P1130 红牌 (记忆化)

    记忆化有时候调起来还是很恼火的

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    const int N = 2005;
    int a[N][N],  f[N][N], n , m;
    
    int dfs(int i,int j)
    {
    	if(f[i][j] != -1)return f[i][j];
    	if(i == n + 1)
    	{
    		return f[i][j] = 0;
    	}
    	int x = 0x3f3f3f3f, y = 0x3f3f3f3f; // 主义这里要初始化得足够大 
    	x = dfs(i + 1, j);	
    	int jj = j + 1;
    	if(jj > m)jj -= m; //如果超出就直接回去访问第一个 
    	y = dfs(i + 1,jj);
    	f[i][j] = min(x,y) + a[i][j];
    	return f[i][j];
    }
    
    void print()
    {
    	for(int i = 1;i <= n;i ++)
    	{
    		for(int j = 1;j <= m + 1 ;j ++)
    		{
    			cout << f[i][j] << " ";
    		}
    		cout << endl;
    	}
    }
    int main()
    {
    	cin >> n >> m;
    	fill(f[0],f[0] + N * N,-1);
    	for(int i = 1;i <= m ;i ++)
    	{
    		for(int j = 1;j <= n ;j ++)
    		{
    			scanf("%d",&a[j][i]);
    		}	
    	}
    	int ans = 1 << 30;  //这里要把ans 取得足够大 
    	for(int i = 1;i <= m;i ++)
    	{
    		ans = min(ans,dfs(1,i));
    	}
    	cout << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    8.请描述基本数据类型和引用数据类型的区别?
    7.在第4题中Hello.class所在路径下, 输入命令:java Hello.class,会出现什么结果,为什么?
    6.如果第4题中在DOS命令下输入:java Hello 出现以下结果:Exception in thread “main” java.lang.NoClassDefFoundError: Hello
    5.如果第4题中在DOS命令下输入:java Hello 出现以下结果:Bad command or the file name 可能是什么原因?请说明理由。
    C# 反射技术应用
    C# 中的委托和事件
    类和结构的区别
    c#接口和抽象类的区别
    Repeater 控件使用总结
    SpringMvc+jquery easyui模块开发7步骤
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12459731.html
Copyright © 2011-2022 走看看