Codeforces Round 847 (Div. 3)D. Matryoshkas,Codeforces Round 878 (Div. 3)B. Binary Cafe

Problem - D - Codeforces

//gyeolhada...in bloom...dream...ricky
//string s="ricky";s.insert(0,"hello ");-->hello ricky
//transform(s.begin(), s.end(), s.begin(), ::tolower);
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
#define Y cout<<"YES"<<endl
#define N cout<<"NO"<<endl
void func()
{
	ll n;
	cin >> n;
	multiset<int>e;
	//可以重复元素的升序序列
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		e.insert(x);
	}
	ll a = *e.begin();
	//e.begin()返回multiset中起始位置元素的迭代器
	//e.end()返回multiset中最后一个元素后面的迭代器
	ll ans = 1;//默认先一个序列
	while (e.size())
	{
		auto it = e.find(a);//it为迭代器
		if (it != e.end())//在e中找得到
		{
			e.erase(it);//删掉
			a++;
		}
		else//找不到即一个序列结束
		{
			ans++;
			a = *e.begin();
		}
	}
	cout << ans << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}

Problem - B - Codeforces

//gyeolhada...in bloom...dream...ricky
//string s="ricky";s.insert(0,"hello ");-->hello ricky
//transform(s.begin(), s.end(), s.begin(), ::tolower);
//2^30=1e9+73741824
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
#define Y cout<<"YES"<<endl
#define N cout<<"NO"<<endl	1111111112
//最大钱数N=1e9<2^30
ll a[32];
void init()
{
	for (int i = 0, j = 1; i <= 30; i++)
	{
		a[i] = j;
		j *= 2;
	}
}
void func()
{
	ll n, k;
	cin >> n >> k;
	//(全用完)n元的最多种购买方案也就是1~n都可以用二进制表达出来
	if (k >= 30)
		cout << n + 1 << endl;//0元也是一种方案
	else if (a[k] < n + 1)
		cout << a[k] << endl;
	else
		cout << n + 1 << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	init();
	while (t--)
	{
		func();
	}
	return 0;
}

Problem - B - Codeforces

#include<bits/stdc++.h>
using namespace std;
void func()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int len = 2;
	int cur = 2;
	char c = s[0];
	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] == c)
		{
			cur++;
			len = max(len, cur);
		}
		else
		{
			cur = 2;
			c = s[i];
		}
	}
	cout << len << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}

Problem - B - Codeforces

矩阵之前的差值相加最大

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 50 + 5;
ll a[N][N];
void func()
{
	int n;
	cin >> n;
	ll maxx =(ll) n * n;
	int minn = 1;
	bool flag = 0;
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			for (int j = 0; j < n; j++)
			{
				if (j % 2 == 0)
					a[i][j] = (minn++);
				else
					a[i][j] = (maxx--);
			}
		}
		else
		{
			for (int j = n - 1; j >= 0; j--)
			{
				if (j % 2 == 0)
					a[i][j] = (maxx--);
				else
					a[i][j] = (minn++);
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值