Codeforces Round #642 (Div. 3)
题目链接:http://codeforces.com/contest/1353
视频讲解链接:https://www.bilibili.com/video/BV1Fz4y1d7nt
代码:
A
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 // 2 // main.cpp 3 // CF 4 // 5 // Created by 韩金宇 on 2020/5/15. 6 // Copyright © 2020 韩金宇. All rights reserved. 7 // 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <iostream> 12 #include <algorithm> 13 #include <vector> 14 #include <queue> 15 #include <set> 16 #include <map> 17 #include <list> 18 #include <map> 19 #include <string> 20 #include <math.h> 21 #include <stdlib.h> 22 #include <time.h> 23 using namespace std; 24 typedef double db; 25 typedef long long ll; 26 int main() 27 { 28 #ifdef ONLINE_JUDGE 29 #else 30 freopen("in.txt","r",stdin); 31 #endif 32 int t; 33 scanf("%d",&t); 34 while(t--){ 35 ll n,m; 36 scanf("%lld%lld",&n,&m); 37 if(n==1) 38 printf("0\n"); 39 else if(n==2) 40 printf("%lld\n",m); 41 else 42 printf("%lld\n",m<<1); 43 44 } 45 return 0; 46 }
B
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// // main.cpp // CF // // Created by 韩金宇 on 2020/5/15. // Copyright © 2020 韩金宇. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=2e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ int n,k; scanf("%d%d",&n,&k); int a[50],b[50]; for(int i=0;i<n;i++) scanf("%d",a+i); for(int i=0;i<n;i++) scanf("%d",b+i); sort(a,a+n); sort(b,b+n,greater<int>()); int kk=0; for(int i=0;i<n;i++) { if(b[i]>a[i]) { if(kk>=k) break; swap(a[i],b[i]); kk++; } } int sum=0; for(int i=0;i<n;i++) sum+=a[i]; printf("%d\n",sum); } return 0; }
C
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// // main.cpp // CF // // Created by 韩金宇 on 2020/5/15. // Copyright © 2020 韩金宇. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=2e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); ll sum=0,beg=8; for(int i=1;i<=(n/2);i++){ sum+=(i*beg); beg+=8; } printf("%lld\n",sum); } return 0; }
D
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// // main.cpp // CF // // Created by 韩金宇 on 2020/5/15. // Copyright © 2020 韩金宇. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=2e5+10; pair<int,int > p3,p4,p; struct cmp{ bool operator()(const pair<int, int> p1,const pair<int, int> p2){ if(p1.second-p1.first==p2.second-p2.first) return p1.first>p2.first; return p1.second-p1.first<p2.second-p2.first; } }; priority_queue<pair<int, int>,vector<pair<int, int>>,cmp> q; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); q.push({1,n}); int a[maxn]; int ops=1; while(q.size()){ int l=q.top().first; int r=q.top().second; int mid=(l+r)/2; q.pop(); a[mid]=ops++; if(l<=mid-1) q.push({l,mid-1}); if(r>=mid+1) q.push({mid+1,r}); } for(int i=1;i<=n;i++){ printf("%d ",a[i]); } printf("\n"); } return 0; }