File tree Expand file tree Collapse file tree 6 files changed +216
-0
lines changed
lanqiao/src/main/java/lq250111 Expand file tree Collapse file tree 6 files changed +216
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ cout << 31 << endl;
8+ }
9+
10+ signed main () {
11+ ios::sync_with_stdio (false );
12+ cin.tie (nullptr );
13+
14+ int t = 1 ;
15+ // cin >> t;
16+ while (t--) {
17+ solve ();
18+ }
19+ return 0 ;
20+ }
21+ /*
22+ 哪来的AC【算法赛】
23+ */
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ int n, m;
8+ cin >> n >> m;
9+
10+ vector<int > a (n);
11+ for (int i = 0 ; i < n; ++i) {
12+ cin >> a[i];
13+ }
14+
15+ std::sort (a.begin (), a.end ());
16+ int ans = INT_MAX;
17+ for (int i = m - 1 ; i < n; ++i) {
18+ ans = min (ans, a[i] - a[i - m + 1 ]);
19+ }
20+ cout << ans << endl;
21+ }
22+
23+ signed main () {
24+ ios::sync_with_stdio (false );
25+ cin.tie (nullptr );
26+
27+ int t = 1 ;
28+ // cin >> t;
29+ while (t--) {
30+ solve ();
31+ }
32+ return 0 ;
33+ }
34+ /*
35+ 酒店安排【算法赛】
36+ */
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ ll n, m, k;
8+ cin >> n >> m >> k;
9+
10+ ll ans = min (n / 2 , m);
11+ n -= ans * 3 ;
12+ k -= n + m;
13+
14+ k = max (k, 0LL );
15+ ll need = (k + 2 ) / 3 ;
16+ ans -= need;
17+
18+ cout << ans << endl;
19+ }
20+
21+ signed main () {
22+ ios::sync_with_stdio (false );
23+ cin.tie (nullptr );
24+
25+ int t = 1 ;
26+ cin >> t;
27+ while (t--) {
28+ solve ();
29+ }
30+ return 0 ;
31+ }
32+ /*
33+ 男女搭配【算法赛】
34+ */
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ ll n;
8+ cin >> n;
9+
10+ ll ans = n * (n - 1 ) / 2 + (n - 1 ) * 2 + n + 1 ;
11+ cout << ans << endl;
12+ }
13+
14+ signed main () {
15+ ios::sync_with_stdio (false );
16+ cin.tie (nullptr );
17+
18+ int t = 1 ;
19+ // cin >> t;
20+ while (t--) {
21+ solve ();
22+ }
23+ return 0 ;
24+ }
25+ /*
26+ 排列高手【算法赛】
27+
28+ 提示:将 1 和 2 放到数组的两端即可得到最优排列
29+ 考虑一种情况,假设排列中没有数字 1,那么所有的子数组 mex 都会是 1.
30+ 当我们把数字 1 放入排列中时,有一部分包含数字 1 的子数组的最小排除数会增加,我们称这部分子数组为“受影响的子数组”。
31+ 当我们把数字 1 放在第 i 个位置时,受影响的子数组的数量为 i*(n-i+1)。很明显,当 i 是 1 或 n 时,受影响的子数组数量会最小,为 n。
32+ 1、不包含数字 1 的子数组:数量为 n(n-1)/2
33+ 2、包含数字 1 但不包含数字 2 的子数组:数量是 n-1,mex=2,贡献为 (n-1)*2
34+ 3、包含数字 1 且包含数字 2 的子数组:数量是 1,贡献是 n+1。
35+ */
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ int n;
8+ cin >> n;
9+
10+ vector<int > a (n);
11+ for (int i = 0 ; i < n; ++i) {
12+ cin >> a[i];
13+ }
14+
15+ int mx = 0 ;
16+ vector<int > vis (n + 1 );
17+ for (int i = 0 ; i < n; ++i) {
18+ if (mx > a[i]) vis[a[i]] = 1 ;
19+ mx = max (mx, a[i]);
20+ }
21+
22+ mx = 0 ;
23+ for (int i = n - 1 ; i >= 0 ; --i) {
24+ if (mx > a[i]) vis[a[i]] = 1 ;
25+ if (vis[a[i]]) mx = max (mx, a[i]);
26+ }
27+
28+ int ans = 0 ;
29+ for (int i = 1 ; i <= n; ++i) {
30+ ans += vis[i];
31+ }
32+ cout << ans << endl;
33+ }
34+
35+ signed main () {
36+ ios::sync_with_stdio (false );
37+ cin.tie (nullptr );
38+
39+ int t = 1 ;
40+ // cin >> t;
41+ while (t--) {
42+ solve ();
43+ }
44+ return 0 ;
45+ }
46+ /*
47+ 混乱的草稿纸【算法赛】
48+ */
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+ typedef long long ll;
5+
6+ void solve () {
7+ int n;
8+ cin >> n;
9+
10+ vector<int > a (n), cnt (1e6 + 5 );
11+ for (int i = 0 ; i < n; ++i) {
12+ cin >> a[i];
13+ cnt[a[i]]++;
14+ }
15+
16+ int ans = 0 ;
17+ for (int i = 1 ; i <= 1e6 ; ++i) {
18+ for (int j = 1 ; j <= cnt[i]; ++j) {
19+ if (cnt[j] >= i) {
20+ ans++;
21+ }
22+ }
23+ }
24+ cout << ans << endl;
25+ }
26+
27+ signed main () {
28+ ios::sync_with_stdio (false );
29+ cin.tie (nullptr );
30+
31+ int t = 1 ;
32+ // cin >> t;
33+ while (t--) {
34+ solve ();
35+ }
36+ return 0 ;
37+ }
38+ /*
39+ 完美数对【算法赛】
40+ */
You can’t perform that action at this time.
0 commit comments