Daliy Algorithm (Mathematics, Greed, Thinking)-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


The hard work you put out early in the morning and late in the evening, you do n’t want to train. When you feel too tired but still have to gritt your teeth, it is chasing your dreams, do n’t care about what the end is, and enjoy the journey, maybe you ca n’t Achieve your dreams, but there must be greater things to follow. mamba out ~

2020.4.22


Constant Palindrome Sum

Occupy tomorrow to make up the process

#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();
	}
}

Guess you like

Origin www.cnblogs.com/wlw-x/p/12757948.html