BUPT Spring 2020 Combat #18, Southern and Volga Russian Regional Contes 2019

------------恢复内容开始------------

A.Berstagram  CodeForces 1250A

开两个数组,一个用来储存当前数列,另一个id[i]用来储存id为i的博客的当前位置,模拟即可(用链表写的我就是个five

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int mx[1000005],mn[1000005],a[1000005],id[1000005];
 4 int main(){
 5     int n,m;scanf("%d%d",&n,&m);
 6     for (int i=1;i<=n;i++) mx[i]=mn[i]=a[i]=id[i]=i;
 7     for (int i=1;i<=m;i++){
 8         int x;scanf("%d",&x);
 9         int p=id[x];int y=a[p-1];
10         if (p==1) continue;
11         
12         swap(a[p-1],a[p]);
13         id[y]++;id[x]--;
14         mx[y]=max(mx[y],id[y]);
15         mn[x]=min(mn[x],id[x]);
16     }
17     for (int i=1;i<=n;i++) printf("%d %d\n",mn[i],mx[i]);
18 }

B.The Feast and the Bus  CodeForces 1250B

扫描二维码关注公众号,回复: 11206963 查看本文章

先给输入的组按人数排序

对于巴士的大小s,每次循环优先让人数最大的组上车,然后判断能不能让人数最小的上车,能上就上,之后除去上了车的组继续循环。

而巴士的大小存在一个范围,即>=最大组的人数,<=最大组的人数+次大组的人数,其次巴士的大小必然为两组的人数的和,不然会产生浪费,所以我们先用set进行预处理

 1 #include <iostream>
 2 #include<queue>
 3 #include<map>
 4 #include<utility>
 5 #include<vector>
 6 #include<algorithm>
 7 #include<cstring>
 8 #include<string>
 9 #include<stdio.h>
10 #include<sstream>
11 #include<fstream>
12 #include<cmath>
13 #include<set>
14 #include<math.h>
15 using namespace std;
16 typedef  long long  ll;                    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 typedef pair<int, int> P;
18  int m, n, t,f,w,x;
19 int dat[10000+105] = {};
20 set<int> s;
21 void solve() {
22     for (int i = 0; i < m; i++) {
23         int temp;
24         cin >> temp;
25         dat[temp]++;
26     }
27     sort(dat + 1, dat + n + 1);
28     ll ans  = 9223372036854775807;
29     if (n == 1) {
30         ans = dat[1];
31         cout << ans;
32         return;
33     }
34     s.insert(dat[n]);
35     for(int i=1;i<n;i++)
36         for (int j = 1; j <=n; j++) {
37             if ((dat[i] + dat[j] > dat[n])&&(i!=j))
38             s.insert(dat[i] + dat[j]);
39         }
40     for (set<int>::iterator itr = s.begin(); itr != s.end();++itr) {
41         int f = 1, end = n;
42         int s = *itr;
43         int r = 0;
44         while (end>=f)
45         {
46             if (end == f) { r++; break; }
47             if (dat[end] + dat[f] <= s) {
48                 end--;
49                 f++;
50             }
51             else
52                 end--;
53             r++;
54         }
55         if (((ll)r) * s < ans)
56             ans = ((ll)r) * s;
57     }
58     cout << ans;
59 }
60 int main() {
61     cin >> m >> n;
62     solve();
63         return 0;
64 }

C. Trip to Saint Petersburg  CodeForces 1250C

线段树 目前不会


E.The Coronation  CodeForces 1250E

看了题解才知道是并查集,wtcl。。。

题意:给定几个01字符串,若相同位置有k个字符相同,则认为他们相似,问最少反转多少个字符串,让他们两两相似

猜你喜欢

转载自www.cnblogs.com/pophirasawa/p/12901723.html