蓝桥普及组打卡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 回复 打赏 收藏 转发到动态 举报

50,623

• 近7日
• 近30日
• 至今

刷题！