A TubeTube Feed
题目大意:
解题思路:
狠狠的贪,每次能看电视就都看,找出能看的最大娱乐值
参考代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int q, n, t;
struct node {
int id;
int a, b;
} s[N];
bool cmp(node x, node y) {
return x.b > y.b;
}
int main() {
cin >> q;
while (q--) {
cin >> n >> t;
for (int i = 1; i <= n; i++) cin >> s[i].a;
for (int i = 1; i <= n; i++) cin >> s[i].b;
int ans, ma = 0;
for (int i = 1; i <= n; i++) {
if (t >= s[i].a) {
if (ma < s[i].b) {
ma = s[i].b;
ans = i;
}
}
t--;
}
if (ma) cout << ans << endl;
else cout << -1 << endl;
}
return 0;
}
B Karina and Array
题目大意:
解题思路:
排序,找到最大的两个数或者最小的两个数
参考代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
int t, n;
ll a[N];
ll inf = 9999999999999999;
ll ans;
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
sort(a + 1, a + n + 1);
ans = max(a[1] * a[2], a[n] * a[n - 1]);
cout << ans << endl;
}
return 0;
}
C Bun Lover
题目大意:
解题思路:
推式子
参考代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
ll t, n;
ll ans;
int main() {
cin >> t;
while (t--) {
cin >> n;
ans = 2 + 2 * n + n * n;
cout << ans << endl;
}
return 0;
}
本文提供了几道编程竞赛题目,包括A题的贪心策略——在给定时间内最大化娱乐值,B题的排序应用——寻找数组中最大或最小两数之积,以及C题的数学计算——求解与n相关的公式。每道题目都附有解题思路和参考代码。
1165

被折叠的 条评论
为什么被折叠?



