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


    luogu -P1044 栈

    卡特兰数

    #include <iostream>
    #include <algorithm>
    #include <stack>
    #include <string>
    #include <cstdio>
    
    using namespace std;
    const int N = 50;
    int n, f[N];
    int main()
    {
    	int n;
    	cin >> n;
    	long long sum = 0;
    	f[0] = 1; f[1] = 1;
    	for(int i = 2;i <= n ;i ++)
    		for(int j = 0;j < i ;j ++)
    		{
    			f[i] += f[j] * f[i-j-1];
    		}
    	cout << f[n] << endl;
    	return 0;	
    } 
    

    luogu -P1149 火柴棒等式

    暴力枚举就ok
    评测姬莫名卡我24 最后一个re 本地正确 最后无奈特判一下AC希望大佬如果发现了哪里有问题可以指正

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    using namespace std;
    const int N = 10000;
    int dict[] = {6,2,5,5,4,5,6,3,7,6};
    int f[N];
    void getsum()
    {
    	for(int i = 0;i <= 9999;i ++)
    	{
    		string s = to_string(i);
    		int sum = 0;
    		for(int j = 0;j < s.size();j ++)
    		{
    			sum += dict[s[j] - '0'];
    		}
    		f[i] = sum;
    	}
    }
    int main()
    {
    	int n ;getsum();
    	cin >> n;
    	int t = n - 4,ans = 0;
    	// 评测机抽风 本地能过 提交最后一个re 自己提交得时候加入了个特判   
    	for(int i = 0;i <= 9999;i ++)
    	{
    		int a = f[i];
    		if(a >= t)continue; // 后面就被剪掉 
    		for(int j = 0;j <= 9999;j ++)
    		{
    			int b = f[j];
    			if(a + b >= t)continue; // 最后一位没机会了 
    			else{
    				int c = i + j;int num = f[c];
    				if(num == t - a - b)ans++;
    			}	
    		}
    	}	
    	cout << ans;
    	return 0;
    }
    

    lqb 求和求平均值

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    
    int main()
    {
    	double x, sum = 0;
    	for(int i = 1;i <= 10;i ++)
    	{
    		cin >> x;
    		sum += x;	
    	}	
    	cout << sum << endl;
    	printf("%.1f",sum / 10);
    	return 0;
    } 
    

    lqb 逆序输出

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    void fun(int n)
    {
    	if(n == 0)return;
    	if(n > 0)cout << n % 10;
    	func(n / 10);
    }
    
    int main()
    {
    	int n;
    	cin >> n;
    	fun(n);
    	return 0;	
    } 
    

    lqb 字符串长度

    #include <iostream>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	string s;
    	cin >> s;
    	cout << s.size() <<endl;
    	return 0;
    }
    

    lqb 找零钱

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    int a[3];
    int main()
    {
    	int n , x;
    	cin >> n;
    	for(int i = 1;i <= n;i ++)
    	{
    		cin >> x;
    		if(x == 25)a[1]++;
    		if(x == 50){
    			if(a[1] >= 1)
    			{
    				a[1]--;a[2]++;
    			}else{
    				cout << "NO" << endl;
    				return 0;
    			}
    		}
    		if(x == 100)
    		{
    			if(a[1] >= 3 && a[2] == 0)
    			{
    				a[3]++;a[1]-=3;
    			}
    			else if(a[1] >= 1 && a[2] >= 1)
    			{
    				a[3]++;a[1]--;a[2]--;
    			}else{
    				cout << "NO" << endl;
    				return 0;
    			}
    		}
    	}
    	cout << "YES" << endl;
    	return 0;
    }
    

    lqb 多阶乘计算

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    
    using namespace std;
    
    int n , k , m;
    
    long long f(int n,int s)
    {
    	if(n <= 0 || n == 1)return 1;
    	else return n * f(n - s,s); 
    }
    
    int main()
    {
    	cin >> n >> k >> m;
    	long long  sum = 0;
    	for(int i = 1;i <= k;i ++)
    	{
    		//cout << f(n,i) << endl;
    		sum += f(n,i);
    	}
    	if(m == 1)
    	{
    		cout << sum << endl;
    	}
    	if(m == 2)
    	{
    		int t = 0;
    		while(sum)
    		{
    			t = t + sum % 10;
    			sum /= 10;
    		}
    		cout << t << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    什么是RUP
    oracle 导入导出
    jsp 标签
    java json 交互
    Spring MVC 学习过程遇到的问题
    Spring 与其他ORM 框架结合 作数据持久层解析 (转)
    Spring mvc 中快速获取request、reponse、session
    Spring 数据绑定
    spring mvc 请求对应控制器的解析策略配置
    spring 的几种注解
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12405284.html
Copyright © 2011-2022 走看看