A - 检查宿舍卫生
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int a, b, c, d, e;
int sum;
} f[N];
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int mx = -1, sum, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
f[i] = {a, b, c, d, e};
sum = a + b + c + d + e;
if (sum < 85)
ans++;
mx = max(mx, sum);
}
if (mx >= 85)
cout << ans << " " << mx;
else
cout << n << " No";
return 0;
}
B - 小 I 的小姐姐
注意编号是 0 − n − 1 0-n-1 0−n−1
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int w1, w2, w3, id;
int sum;
} f[N];
bool cmp(node a, node b)
{
return a.sum > b.sum;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
{
f[i].id = i;
cin >> f[i].w1 >> f[i].w2 >> f[i].w3;
f[i].sum = f[i].w1 * 0.7 + f[i].w2 * 0.2 + f[i].w3 * 0.1;
}
sort(f, f + n, cmp);
cout << f[0].id;
return 0;
}
C - 选票统计
注意排序是 1 − m + 1 1-m+1 1−m+1
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int id, num;
} f[N];
bool cmp(node a, node b)
{
return a.num > b.num;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> m >> n;
for (int i = 1; i <= n; i++)
{
cin >> x;
f[x].id = x;
f[x].num++;
}
sort(f + 1, f + 1 + m, cmp);
cout << f[1].id << endl;
cout << f[1].num << endl;
return 0;
}
D - 小 I 选宾馆
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int p, s, id;
} f[N];
bool cmp(node a, node b)
{
if (a.p == b.p)
{
if (a.s == b.s)
{
return a.id < b.id;
}
return a.s > b.s;
}
return a.p > b.p;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
f[i].id = i;
cin >> f[i].p >> f[i].s;
}
sort(f + 1, f + 1 + n, cmp);
cout << f[1].id;
return 0;
}
E - 小鑫の日常系列故事(十)——排名次
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
string name;
int grade;
} f[N];
bool cmp(node a, node b)
{
return a.grade > b.grade;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> f[i].name >> f[i].grade;
}
sort(f + 1, f + 1 + n, cmp);
for (int i = 1; i <= n; i++)
{
cout << f[i].name << " " << f[i].grade << endl;
}
return 0;
}
F - 最终排名
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int num, id, x;
} f[N];
bool cmp(node a, node b)
{
if (a.num == b.num)
return a.x < b.x;
return a.num > b.num;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> f[i].id >> f[i].num;
f[i].x = i;
}
sort(f + 1, f + 1 + n, cmp);
for (int i = 1; i <= n; i++)
{
cout << f[i].id << " " << f[i].num << endl;
}
return 0;
}
G - 选夫婿1
结构体数组不要开太大 不然会 M L E MLE MLE
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e3 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
string name;
int h, w;
} f[N];
bool cmp(node a, node b)
{
if (a.h == b.h)
return a.w < b.w;
return a.h < b.h;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, h1, h2, w1, w2, flag = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> f[i].name >> f[i].h >> f[i].w;
}
cin >> h1 >> h2 >> w1 >> w2;
sort(f + 1, f + n + 1, cmp);
for (int i = 1; i <= n; i++)
{
if (f[i].h < h1 || f[i].h > h2 || f[i].w < w1 || f[i].w > w2)
continue;
cout << f[i].name << " " << f[i].h << " " << f[i].w << endl;
flag = 1;
}
if (flag == 0)
cout << "No";
return 0;
}
H - 老–质价比
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e3 + 10;
int v[N], n, m, k, x, t, T;
struct node
{
int m, p;
} f[N];
bool cmp(node a, node b)
{
if (a.m == b.m)
return a.p > b.p;
return a.m < b.m;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> f[i].m;
}
for (int i = 1; i <= n; i++)
{
cin >> f[i].p;
}
sort(f + 1, f + 1 + n, cmp);
for (int i = 1; i <= n; i++)
{
cout << f[i].m << " " << f[i].p << endl;
}
return 0;
}
∗
∗
下次一定
∗
∗
**下次一定**
∗∗下次一定∗∗