CF2A
CF743C
CF545C
$$CF2A$$
$利用map统计每个选手分数,统计出选手的最大分值,循环遍历求出满足条件的第一个值即为正确答案$
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define de(a) cout << #a << " = " << a << "\n";
#define deg(a) cout << #a << " = " << a << " ";
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
#define lowbit(x) ((x) & - (x))
#define LF(x) fixed<<setprecision(x)
//vector<vector<int>> ma((n+10),vector<int>(m+10));
typedef pair<int, int> PII;
const double pi = acos(-1.);
int qmi(int a, int b, int q) {
int res = 1 % q;
while (b) {
if (b & 1)res = res * a % q;
a = a * a % q;
b >>= 1;
}
return res;
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0}; //L R D U
int n, m;
string str;
void solve() {
cin >> n;
map<string, int> mp;
int ans = -1e18;
string name = "";
vector<pair<string, int>> q(n + 1);
for (int i = 1; i <= n; i++) {
string u;
int v;
cin >> u >> v;
q[i] = {u, v};
mp[u] += v;
}
for (int i = 1; i <= n; i++)ans = max(ans, mp[q[i].first]);
map<string, int> mp1;
for (int i = 1; i <= n; i++) {
mp1[q[i].first] += q[i].second;
if (mp1[q[i].first] >= ans && mp[q[i].first] == ans) {
name = q[i].first;
break;
}
}
cout << name << "\n";
}
signed main() {
IOS
int T = 1;
// cin>>T;
while (T--) solve();
return 0;
}
$$CF743C$$
$算术推导:$
$\frac {1}{x} + \frac{1}{y} + \frac {1}{z} = \frac {2}{n}$
$看n与x,y,z的数据范围 令z=n$
$则公式为:$
$\frac {1}{x} + \frac{1}{y} + \frac {1}{n} = \frac {2}{n}$
$\frac {1}{x} + \frac{1}{y} = \frac {1}{n}$
$\frac {1}{n+1} + \frac{1}{n*(n+1)} = \frac {1}{n}$
$x=n+1$ $~~~$ $y=n*(n+1)$ $~~~$ $z=n$
$注意当n<=1时是无解$
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define de(a) cout << #a << " = " << a << "\n";
#define deg(a) cout << #a << " = " << a << " ";
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
#define lowbit(x) ((x) & - (x))
#define LF(x) fixed<<setprecision(x)
//vector<vector<int>> ma((n+10),vector<int>(m+10));
typedef pair<int, int> PII;
const double pi = acos(-1.);
int qmi(int a, int b, int q) {
int res = 1 % q;
while (b) {
if (b & 1)res = res * a % q;
a = a * a % q;
b >>= 1;
}
return res;
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0}; //L R D U
int n, m;
string str;
void solve() {
/*
1/x+1/y+1/z=2/n
1/x+1/y+1/n=2/n
1/x+1/y=1/n
(1/(n+1))+(1/(n*(n+1)))=1/n
*/
cin >> n;
if (n <= 1)cout << "-1\n";
else cout << n << ' ' << n + 1 << ' ' << n*(n + 1);
}
signed main() {
IOS
int T = 1;
// cin>>T;
while (T--) solve();
return 0;
}
$$CF545C$$
$贪心:第一棵树向左倒,最后一颗树向右倒,中间的树能先左倒就向左倒,能先右倒就向右倒,则为正确答案.$
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define de(a) cout << #a << " = " << a << "\n";
#define deg(a) cout << #a << " = " << a << " ";
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
#define lowbit(x) ((x) & - (x))
#define LF(x) fixed<<setprecision(x)
//vector<vector<int>> ma((n+10),vector<int>(m+10));
typedef pair<int, int> PII;
const double pi = acos(-1.);
int qmi(int a, int b, int q) {
int res = 1 % q;
while (b) {
if (b & 1)res = res * a % q;
a = a * a % q;
b >>= 1;
}
return res;
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0}; //L R D U
int n, m;
string str;
void solve() {
cin >> n;
vector<PII> q(n + 1);
for (int i = 1, u, v; i <= n; i++) {
cin >> u >> v;
q[i] = {u, v};
}
int ans = 1;
for (int i = 2; i < n; i++) {
if (q[i].first - q[i - 1].first > q[i].second)ans++;
else if (q[i + 1].first - q[i].first > q[i].second)ans++, q[i].first += q[i].second;
}
cout << min(n, ans + 1) << "\n";
}
signed main() {
IOS
int T = 1;
// cin>>T;
while (T--) solve();
return 0;
}