A.计时器,计算A->1就ans++;B->2就ans++,以此类推,做个桶计时
// Problem: A. Problemsolving Log
// Contest: Codeforces - Codeforces Round 916 (Div. 3)
// URL: https://codeforces.com/contest/1914/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
B.排序输入前k个(一个比一个大)后面都小即可.
// Problem: B. Preparing for the Contest
// Contest: Codeforces - Codeforces Round 916 (Div. 3)
// URL: https://codeforces.com/contest/1914/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
C.贪心,边做下一个任务边比对大小.
// Problem: C. Quests
// Contest: Codeforces - Codeforces Round 916 (Div. 3)
// URL: https://codeforces.com/contest/1914/problem/C
// Memory Limit: 256 MB
// Time Limit: 2500 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
D.排序对前3个a[i],b[i],c[i].求最大ans=a[i]+b[j]+c[k];
#include
#include
#include
using namespace std;
void solve(){
int n;
cin>>n;
vector > a,b,c;
for(int i=1;i<=n;i++){
int x;
cin>>x;
a.push_back({x,i});
}
for(int i=1;i<=n;i++){
int x;
cin>>x;
b.push_back({x,i});
}
for(int i=1;i<=n;i++){
int x;
cin>>x;
c.push_back({x,i});
}
sort(a.begin(),a.end(),greater>());
sort(b.begin(),b.end(),greater>());
sort(c.begin(),c.end(),greater>());
int ans=-2;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
if(a[i].second!=b[j].second && a[i].second!=c[k].second && b[j].second!=c[k].second){
int res=a[i].first+b[j].first+c[k].first;
ans=max(ans,res);
}
}
}
}
cout<>q;
while(q--){
solve();
}
return 0;
}
D.dfs法待续
E1.dfs法(n<6)
// Problem: E1. Game with Marbles (Easy Version)
// Contest: Codeforces - Codeforces Round 916 (Div. 3)
// URL: https://codeforces.com/contest/1914/problem/E1
// Memory Limit: 256 MB
// Time Limit: 3500 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
E2.找到正确思路,如果a[1].x+a[1].y>a[2].x+a[2].y,这种排序方式,那么一定是最优解.
// Problem: E2. Game with Marbles (Hard Version)
// Contest: Codeforces - Codeforces Round 916 (Div. 3)
// URL: https://codeforces.com/contest/1914/problem/E2
// Memory Limit: 256 MB
// Time Limit: 3500 ms
//
// Powered by CP Editor (https://cpeditor.org)
//へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include