zoukankan      html  css  js  c++  java
  • Daliy Algorithm (数学,BF,思维)-- day 62

    Nothing to fear

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


    RGB Triplets

    思路: 先将所有可能的结果计算出来
    然后从头开始只看i 和 j 将不满足条件的 k 给去除即可

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    string s;
    void slove()
    {
    	int n;
    	cin >> n >> s;
    	ll ans = 0;
    	int R = 0 ,G = 0 , B= 0;
    	for(char c : s)
    	{
    		if(c == 'R')R++;
    		if(c == 'B')B++;
    		if(c == 'G')G++;
    	}
    	ans = (ll) R * G * B;
    
    	for(int i = 0 ;i < n ;i ++)
    	{
    		for(int j = i + 1;j < n ;j ++)
    		{
    			if(s[i] == s[j])continue;
    			int k = 2 * j - i;
    			if(k >= n)continue;
    			if(s[k] != s[i] && s[k] != s[j])ans--;
    		}
    	}
    	cout << ans << endl;
    }
    int main()
    {
    	SIS;
    	slove();
    }
    

    Candies

    数学

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t;
    
    void slove()
    {
    	int n;
    	cin >> n;
    	for(int i = 2;i <= n;i ++)
    	{
    		int a = (pow(2,i) - 1);
    		if(n % a == 0){
    			cout << n / a << endl;
    			return;
    		}
    	}
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    Balanced Array

    数学 Bf

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int t , n;
    
    void slove()
    {
    	cin >> n;
    	vector<int> a(n + 1, 0);
    	int t = 2;
    	ll sum = 0;
    	for(int i = 1;i <= n / 2;i ++)
    	{
    		a[i] = t;sum += a[i];t += 2;
    	}
    	t = 1;
    	for(int i = n / 2 + 1;i <= n ;i ++)
    	{
    		if(i == n){
    			a[i] = sum;
    			break;
    		}
    		a[i] = t; 
    		sum = sum - a[i];
    		t += 2;
    	}
    	if(sum % 2 != 0){
    		cout << "YES" << endl;
    		for(int i = 1;i <= n ;i ++)cout << a[i] <<" ";
    			cout << endl;
    		return;
    	}else{
    		cout << "NO" << endl;
    		return;
    	}
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    Alternating Subsequence

    双指针 贪心

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <cassert>
    #include <string>
    #include <cmath>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    #define lowbit(x) (x & -x)
    #define push_back pb
    using namespace std;
    typedef long long ll;
    const int N = 500005;
    const int MAX = 0x7ffffff;
    int t;
    void slove()
    {
    	ll n;
    	cin >> n;
    	int a[N];
    	for(int i = 1;i <= n;i ++)cin >> a[i];
    	ll sum = 0;a[n + 1] = 0;
    	ll i = 1 , m = 0;
    	while(i <= n)
    	{
    		m = a[i]; 
    		while((ll)a[i+1] * a[i] > 0) 
    		{
    			i++; 
    			if(a[i] > m) m = a[i]; 
    		}
    		sum += m;
    		i++;
    	}
    	cout << sum << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    
  • 相关阅读:
    mysql通过data目录恢复数据库
    CentOS安装TortoiseSVN svn 客户端
    CentOS上安装Node.js
    PHP--进行模块化设计
    PHP开发绝对不能违背的安全铁则
    达内培训:php在线端口扫描器
    使用 PHP 限制下载速度
    使用无限生命期Session的方法
    使用php作linux自动执行脚本
    腾讯星座运势api
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12749932.html
Copyright © 2011-2022 走看看