蓝桥普及组打卡2.9

是泡泡 每日一题总教官
云计算领域优质创作者
2023-02-09 18:20:20

1

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1010;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct node {
	string s;
	int id, len;
}a[100];
bool cmp(node x, node y) {
	if(x.len > y.len) return true;
	else if(x.len == y.len && x.s > y.s) return true;
	return false;
}
void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++ )  {
		cin >> a[i].s;
		a[i].id = i;
		a[i].len = a[i].s.size();
	}
	sort(a + 1, a + 1 + n, cmp);
	cout << a[1].id << '\n' << a[1].s;
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

2.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1010;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct node {
	int id, num;
}a[N];
bool cmp(node a, node b) {
	return a.num < b.num;
}
void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++ ) {
		cin >> a[i].num;
		a[i].id = i;
	}
	sort(a + 1, a + 1 + n, cmp);
	for(int i = 1; i <= n; i ++ ) {
		cout << a[i].id << ' ';
	}
	cout << '\n';
	double sum = 0;
	for(int i = n - 1; i >= 1; i -- ) {
		sum += a[n - i].num * i;
	}
	printf("%.2f",sum / n);
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

3

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1e5+10;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int a[N];
void solve() {
	int n, k;
	cin >> n >> k;
	ll sum = 0;
	for(int i = 1; i <= n; i ++ ) cin >> a[i];
	for(int i = 2; i <= n; i ++ ) {
		if(a[i] + a[i - 1] > k) {
			sum += a[i] + a[i - 1] - k;
			a[i] = k - a[i - 1];
		}
	}
	cout << sum;
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

4

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
#define x first
#define y second
#define ms(a,s) memset(a, s, sizeof a);
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
const int mod = 1e6+7;
const int inf = 0x3f3f3f3f;
const int N = 1e6;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int a[N];
void solve() {
	int n, m;
	cin >> m >> n;
	int num = 0;
	int sum = 0;
	for(int i = 1; i <= n; i ++ ) {
		cin >> a[i];
		num = max(num, max(m - a[i] + 1, a[i]));
		sum = max(sum, min(m - a[i] + 1, a[i]));
	}
	cout << sum << '\n' << num;
}
int main()
{
	int t = 1;

//	cin >> t;

	while(t --) {
		solve();
	}

	return 0;
}

 

...全文
26 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,623

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧