Daliy Algorithm -- day 99

Nothing to fear


种一棵树最好的时间是十年前,其次是现在!

那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

2020.8.4


人一我十,人十我百,追逐青春的梦想,怀着自信的心,永不言弃!

Minesweeper

#include <bits/stdc++.h>

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define PI 3.14159265358979323846264338327950L
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
int t;

void slove()
{
	int n;cin >> n;
	string s;cin >> s;
	int ans = 0;
	for(int i = 1;i < n - 1;i ++)
	{
		string l = s.substr(0, i);
		string r = s.substr(i , n - i);
		vector<bool> vis(100 , 0);
		int cnt = 0;
		for(int i = 0;i < l.size();i ++)
			vis[l[i] - 'a'] = 1;
		for(int i = 0;i < r.size();i ++)
			if(vis[r[i] - 'a']){
				cnt++;
				vis[r[i] - 'a'] = 0;
			}
		ans = max(cnt , ans);
	}	
	cout << ans << endl;
}
int main()
{
	SIS;
	slove();
}

Modsum

观察推公式

#include <bits/stdc++.h>

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define PI 3.14159265358979323846264338327950L
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
int t;

void slove()
{
	int n;cin >> n;
	cout << (ll)n * (n - 1) / 2 << endl;
}
int main()
{
	SIS;
	slove();
}
原文地址:https://www.cnblogs.com/wlw-x/p/13436064.html