目录
[A. Problemsolving Log](#A. Problemsolving Log)
[B. Preparing for the Contest](#B. Preparing for the Contest)
[C. Quests](#C. Quests)
[D. Three Activities](#D. Three Activities)
[E1、E2. Game with Marbles (Hard Version)](#E1、E2. Game with Marbles (Hard Version))
[F. Programming Competition](#F. Programming Competition)
A. Problemsolving Log
问题分析:
角色在第i分钟看题,看满对应的事件就算解出题目,遍历一遍即可
cpp
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
typedef pair<int,int>pii;
signed main()
{IOS
use{
int n;cin>>n;
string a;cin>>a;
int t=0;
vct<bool>st(32);
vct<int>cnt(32);
for(int i=0;i<a.LEN;i++){
cnt[a[i]-'A']++;
if(cnt[a[i]-'A']>a[i]-'A')st[a[i]-'A']=1;
}int ans=0;
for(int i=0;i<32;i++){
if(st[i])ans++;
}cout<<ans<<endl;
}
return 0;
}
B. Preparing for the Contest
问题分析:
在一次考试当中,题目难度为1~n,我们可以将其随意排序,如果当前题目难度大于上一个题目,主角会感到一次兴奋,问k次兴奋该怎么排列.
很简单只需要1~k-1正序排列,k~n逆序排列即可,注意这种做法特判k=0
cpp
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
typedef pair<int,int>pii;
signed main()
{IOS
use{
int n,k;cin>>n>>k;
if(k==0){
for(int i=n;i>=1;i--){
cout<<i<<" \n"[i==1];
}
}else {
for(int i=1;i<=k;i++){
cout<<i<<" ";
}
for(int i=n;i>k;i--){
cout<<i<<" ";
}cout<<endl;
}
}
return 0;
}
C. Quests
问题分析:
完成任务可以获得经验,第i个的任务仅当1~i-1个的任务至少执行一次才可执行,初次执行该任务获得经验,之后再执行获得经验,一个任务可以执行多次,如果只能完成k个任务,求经验最大值.
当选择一个任务来完成的时候我们面临着两种选择:
- 选择过去几天里b值最大的执行
- 解锁下一个任务
为了考虑到所有情况,我们可以遍历数组(在一次遍历当中即可解决,故无需担心考虑所有情况时间复杂度),来试验一次解锁当天,剩下的用来进行过去几天里b值最高的任务,更新最大值。
cpp
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
typedef pair<int,int>pii;
signed main()
{IOS
use{
int n,k;cin>>n>>k;
vct<int>a(n+1),b(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int sum=0,ans=0,masb=0;
for(int i=1;i<=min(n,k);i++){
sum+=a[i];
mmax(masb,b[i]);
mmax(ans,sum+(masb*(k-i)));
}
cout<<ans<<endl;
}
return 0;
}
D. Three Activities
题目分析:
此题很简单,个人认为不应该放在D,固定个数为三个数组,仅需排序暴力+判断即可
cpp
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin()+1,a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
typedef pair<int,int>pii;
const int N =1e5+7;
struct ss {
int a,b;
}s1[N],s2[N],s3[N];
bool cmp(ss s1,ss s2){
return s1.a>s2.a;
}
signed main()
{IOS
use{
int n;cin>>n;
for(int i=1;i<=n;i++){cin>>s1[i].a;s1[i].b=i;}
for(int i=1;i<=n;i++){cin>>s2[i].a;s2[i].b=i;}
for(int i=1;i<=n;i++){cin>>s3[i].a;s3[i].b=i;}
sort(s1+1,s1+1+n,cmp);
sort(s2+1,s2+1+n,cmp);
sort(s3+1,s3+1+n,cmp);
int ans=0;
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
for(int k=1;k<=3;k++){
if(s1[i].b!=s2[j].b&&s1[i].b!=s3[k].b&&s2[j].b!=s3[k].b){
mmax(ans,s1[i].a+s2[j].a+s3[k].a);
}
}
}
}cout<<ans<<endl;
}
return 0;
}
E1、E2. Game with Marbles (Hard Version)
题目分析:
E1、E2为同一个体面,仅n大小不同,直接看hard version
在一次博弈当中,先手,自己保留了,且去除了对方的值,故先手收获的价值,对称性可知后手收获价值为,二者公式相同,收获价值相同,故可以按(-1常数项相同可忽略)进行贪心,每次按照最大值找到值进行模拟即可得出答案.
cpp
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin()+1,a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
typedef pair<int,int>pii;
const int N =2e5+7;
struct ss {
int dis;
int idx;
}s[N];
bool cmp(ss s1, ss s2){
return s1.dis>s2.dis;
}
signed main()
{IOS
use{
int n;cin>>n;
vct<int>a(n+1),b(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}for(int i=1;i<=n;i++){
cin>>b[i];
s[i].dis=a[i]+b[i];
s[i].idx=i;
}
sort(s+1,s+1+n,cmp);
int sum1=0,sum2=0;
for(int i=1;i<=n;i++){
if(i%2){
a[s[i].idx]--;
b[s[i].idx]=0;
sum1+=a[s[i].idx];
}else {
b[s[i].idx]--;
a[s[i].idx]=0;
sum2+=b[s[i].idx];
}
}cout<<sum1-sum2<<endl;
}
return 0;
}