• Daliy Algorithm -- day 60


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


    A

    提前判定一共有多少情况
    1.当 a == b ans = 0
    2.当 a > b 时:
    当a b都为奇数 或者a b 都为偶数可以直接一步得到
    否则先执行一次操作将两数变为同性质在进行变换
    当 a < b 时:
    当a b都为奇数 或者或者 a b都为偶数:必须要先将一个
    变换成另外性质的数 在进行加上一个奇数
    其余都是一次变换

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #include <cmath>
    using namespace std;
    
    
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    
    int t;
    
    void work()
    {
    	int a , b;
    	cin >> a >> b;
    	// a只能加上奇数或者减去偶数
    	if(a == b){
    		cout << 0 << endl;
    		return ;
    	}
    	if(a > b)
    	{
    		if((a%2==0 && b%2==0) || (a%2!=0 && b%2!=0))cout << 1 << endl;
    		else cout << 2 << endl;
    	}else{
    		if((a%2==0 && b%2==0) || (a%2!=0 && b%2!=0))cout << 2 << endl;
    		else cout << 1 << endl;
    	}
    }
    int main()
    {
    	cin >> t;
    	while(t--)
    	{
    		work();
    	}
    }
    

    B

    由于是进行相邻变换排序联想到冒泡排序的做法
    需要将每次冒泡排序时交换的j 记录下来最后对照给定的
    变换规则看是否有漏掉的 如果没有即可变换成功否则失败

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #include <cstring>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    
    using namespace std;
    const int N = 1005;
    int a[N] , q[N];
    int vis[N];
    bool v[N];
    int t;
    void slove()
    {
    	memset(vis, 0 , sizeof vis);
    	memset(v , 0 , sizeof v);
    	memset(a , 0 , sizeof a);
    	memset(q , 0 , sizeof q);
    	int n , m;
    	cin >> n >> m;
    	for(int i=1;i<=n;i++){
    		cin >> a[i];
    	}	
    	int tmp = 0;
    	for(int i=0;i<m;i++){
    		cin >> q[i];
    		v[q[i]] = 1;
    	}
    	for(int i = 1;i <= n ;i ++)
    	{
    		for(int j = 1;j <= n - i;j++)
    		{
    			if(a[j] > a[j+1])
    			{
    				int x = a[j];
    				a[j] = a[j+1];
    				a[j+1] = x;	
    				vis[j]++;
    			}
    		}
    	}
    	// 检测一下是否存在没有在 q中得也被++
    	for(int i=0;i<N;i++)
    	{
    		if(v[i] == 0 && vis[i] > 0){
    			cout<< "NO" << endl;
    			return;
    		}
    	}
    	cout << "YES" << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    C

    有的题目看似暴力 实际上排序之后就会有许多优美得性质

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #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 N = 200005;
    int t , n , m;
    void slove()
    {
    	cin >> n >> m;
    	int q[N];
    	int ans[30];
    	char s[N];
    	memset(q , 0 , sizeof q);
    	memset(ans , 0 ,sizeof ans);
    	for(int i = 1;i <= n ;i ++)
    	{
    		cin >> s[i];
    		ans[s[i] - 'a' + 1]++;
    	}
    	for(int i = 1;i <= m;i ++)cin >> q[i];
    	sort(q + 1,q + 1 + m);
    	int i = 1,j = 1;
    	while(j <= m)
    	{
    		int k = m - j + 1;
    		while(i <= q[j] && i <= n)
    		{
    			ans[s[i] - 'a' + 1] += k;
    			i++;
    		}
    		j++;
    	}
    	for(int i = 1;i <= 26 ;i ++)
    	{
    		cout << ans[i] << " ";
    	}
    	cout << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    At:A

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    
    using namespace std;
    typedef long long ll;
    #define PAI 3.14159265358979323846
    const int MAX = 0x7ffffff;
    int t;
    
    int main()
    {
    	SIS;
    	double r;
    	cin >> r;
    	printf("%.20f
    ", 2 * PAI * r); 
    }
    

    At:B

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    
    using namespace std;
    typedef long long ll;
    const int MAX = 0x7ffffff;
    int n , m;
    void slove()
    {
    	cin >> n >> m;
    	ll sum = 0;
    	int x = 0;
    	for(int i = 0;i < m ;i ++)
    	{
    		cin >> x;
    		sum += x;
    	}
    	if(n - sum >= 0)cout << n - sum << endl;
    	else cout << -1 << endl;
    }
    int main()
    {
    	SIS;
    	slove();
    }
    

    At:C

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <vector>
    #include <string>
    #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    
    using namespace std;
    typedef long long ll;
    const int N = 200005;
    const int MAX = 0x7ffffff;
    int n , m;
    int a[N];
    void slove()
    {
    	cin >> n;
    	int x = 0;
    	for(int i = 1;i <= n - 1 ;i ++)
    	{
    		cin >> x;
    		a[x]++;
    	}
    	for(int i = 1;i <= n ;i ++)
    	{
    		cout << a[i] << endl;
    	}
    }
    int main()
    {
    	SIS;
    	slove();
    }
    
  • 相关阅读:
    记录使用Vue开发Chrome插件
    uniapp如何实现USB插入后自动弹出对应软件
    记录分享8个非常实用的Vue自定义指令
    记录一些看起来很叼难的前端面试题
    uniapp热更新和整包更新思路
    01物体检测方法概述
    vuecli之dodo底部统计功能
    vuecli之todo练习1静态资源html
    cuecli之todofooter余下功能
    vuecli之Props配置项
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12734522.html
Copyright © 2020-2023  润新知