zoukankan      html  css  js  c++  java
  • Daliy Algorithm (数学,贪心,思维)-- day 63

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


    Constant Palindrome Sum

    占坑 明天补过程

    #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 N = 200005;
    const int MAX = 0x7ffffff;
    int t;
    void slove()
    {
    	int n , k;
    	cin >> n >> k;
    	vector<int> a(n+1);
    	for(int i = 0;i < n ; ++i)cin >> a[i];
    
    
    	// cnt 数组用于记录 a[i] + a[n-i+1] 出现了多少次
    	vector<int> cnt(2 * k + 1);
    	for(int i = 0;i < n / 2; ++i)
    	{
    		++ cnt[a[i] + a[n-i-1]];
    	}
    	
    	// 得到假设替换这个数这个数可以得到替换得区间
    	
    	vector<int> pref(2 * k + 2);
    	for(int i = 0;i < n / 2;i ++)
    	{
    		int l1 = 1 + a[i],r1 = k + a[i];
    		int l2 = 1 + a[n-i-1],r2 = k + a[n-i-1];
    		if(max(l1,l2) <= min(r1,r2))
    		{
    			++pref[min(l1, l2)];
    			--pref[max(r1, r2) + 1];
    		}else continue;
    	}
    
    	for(int i = 1;i <= 2 * k + 1; ++ i)
    	{
    		cout << pref[i] << " ";
    		pref[i] += pref[i-1];
    	}
    	cout << endl;
    	for(int i = 1;i <= 2 * k + 1; ++ i)
    	{
    		cout << pref[i] << " ";
    	}
    	cout << endl;
    	int ans = 1e9;
    
    	for(int sum = 2; sum <= 2 * k ; ++ sum)
    	{
    		ans = min(ans , (pref[sum] - cnt[sum]) + 
    			(n / 2 - pref[sum]) * 2 );
    	}
    	cout << ans << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    Kana and Dragon Quest game

    #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 , x , m;
    	cin >> x >> n >> m;
    	while(x > m * 10)
    	{
    		if(n == 0)
    		{
    			cout << "NO" << endl;
    			return;
    		}
    		if(n != 0){
    			x = x / 2 + 10;
    			n--;
    		}
    	}
    	cout << "YES" << endl;
    	return ;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    

    Ichihime and Triangle

    #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 a, b , c  ,d;
    	cin >> a >> b >> c >> d;
    	cout << b << " " << c << " " << c << endl;
    }
    int main()
    {
    	SIS;
    	cin >> t;
    	while(t--)
    	{
    		slove();
    	}
    }
    
  • 相关阅读:
    面向对象
    6.jQuery基础_试题
    5.JavaScript操作BOM、DOM对象_试题
    css疑问
    JAVA学习笔记_五JAVA开发中的WEB前端技术
    java学习笔记_mysql随堂考试_错题
    java学习笔记④MySql数据库--03/04 DQL查询
    java学习笔记④MySql数据库--01/02 database table 数据的增删改
    java学习笔记③JAVA核心API编程-01集合框架和泛型
    java学习笔记②JAVA面向对象
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12757948.html
Copyright © 2011-2022 走看看