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


    我太菜了 今天开始补cfdiv3

    CF#629Div3 A

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    int n;
    int main()
    {
    	cin >> n;
    	int a, b ;
    	while(n --)	
    	{
    		cin >> a >> b;
    		if(a % b == 0)printf("0
    ");
    		else{ 
    			printf("%d
    ",b - (a % b));
    		}
    	}
    	return 0;
    } 
    

    CF#629Div3 B

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<cmath>
     
    using namespace std;
     
    int main()
    {
    	int t, ii, n, k, sum, i, j;
    	scanf("%d", &t);
    	for (ii = 0; ii<t; ii++) 
    	{
    		scanf("%d %d", &n, &k);
    		sum = 0;
    		k--;
    		for (i = 0;; i++)
    		{
    			if (sum + i + 1 > k)
    			{
    				break;
    			}
    			sum += i + 1;
    		}
    		k -= sum;
    		i++;
    		for (j = 0; j<n; j++) 
    		{
    			if (j == n - i - 1 || j == n - k - 1)
    			{
    				printf("b");
    			}
    			else
    			{
    				printf("a");
    			}
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    

    CF#629Div3 C

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    void func()
    {
    	int n;
    	cin >> n;
    	string s , a , b;
    	cin >> s;
    	int flag = 0;
    	for(int i = 0;i < s.size() ;i ++)
    	{
    		if(s[i] == '2')
    		{
    			if(flag == 0)
    				a+='1',b+='1';
    			else 
    				a+='0',b+='2';	
    		}
    		else if(s[i] == '0')a+='0',b+='0';
    		else{
    			if(flag == 0)
    			{
    				flag = 1;
    				a+='1';b+='0'; 
    			}
    			else{
    				a += '0';b += '1';
    			}
    		}	
    	}
    	cout << a << endl;
    	cout << b << endl;	
    }
    int main()
    {
    	int t;cin >> t;
    	while(t--)
    	{
    		func();	
    	}	
    	return 0;
    } 
    

    摆动序列

    假dp 真搜索

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    int n, ans;
    bool vis[25];
    void dfs(int a ,int b)
    {
    	if(b > a){
    		for(int i = 1;i < a ;i ++)
    		{
    			if(!vis[i])
    			{
    				ans++;
    				vis[i] = 1;
    				dfs(b , i);
    				vis[i] = 0;
    			}
    		}
    	}
    	else if(a > b){ 
    		for(int i = a + 1;i <= n;i ++)
    		{
    			if(!vis[i])
    			{	
    				ans++;
    				vis[i] = 1;
    				dfs(b , i);
    				vis[i] = 0;
    			}
    		}
    	}
    }
    int main()
    {
    	cin >> n;
    	for(int i = 1;i <= n ;i ++)
    	{
    		vis[i] = 1;
    		for(int j = 1;j <= n ;j ++)
    		{
    			if(i != j)
    			{
    				ans++;
    				vis[j] = 1;
    				dfs(i , j);
    				vis[j] = 0;
    			}
    		}
    	}
    	cout << ans << endl;
    	return 0;
    }
    
    

    拦截导弹

    (o(n^{2}))

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    const int N = 100005;
    int f[N], a[N], n;
    
    int main()
    {
    	while(~scanf("%d",&a[++n]));n--;
    	int ans1 = 0, ans2 = 0;
    	for(int i = n;i >= 1 ;i --)
    	{
    		f[i] = 1;
    		for(int j = i + 1;j <= n ;j ++)
    		{
    			if(a[j] <= a[i])
    				f[i] = max(f[i],f[j] + 1);
    		}
    		ans1 = max(ans1,f[i]);
    	}
    	for(int i = 1;i <= n ;i ++)
    	{
    		f[i] = 1;
    		for(int j = 1;j < i ;j ++)
    		{
    			if(a[j] < a[i])
    				f[i] = max(f[i],f[j] + 1);
    		}
    		ans2 = max(ans2,f[i]);
    	}
    	printf("%d
    %d",ans1,ans2);
    	return 0;
    }
    
  • 相关阅读:
    强人工智能基本问题:全局控制与自组织
    程序员,为未来准备好了吗?
    强人工智能基本问题:自上而下,还是自下而上。
    强人工智能基本问题:神经网络分层还是不分层
    什么阻碍了强人工智能的发展
    人类和强人工智能的关系(人类会被灭掉吗?)
    为什么需要强人工智能
    神经网络和机器学习、强人工智能
    重新开张!
    Xcode文件乱序
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12595469.html
Copyright © 2011-2022 走看看