Codeforces Round 916 (Div. 3)(补题)——A---E

文章目录

  • 一、题目+分析+代码
    • A. Problemsolving Log
    • B. Preparing for the Contest
    • C. Quests
    • D. Three Activities
    • E. Game with Marbles (Easy Version)


一、题目+分析+代码

A. Problemsolving Log

  • 题目大意就是在问题上花费的时间累计到该问题所需时间即可解决该问题,遍历字符串记一下数即可

#include
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define int long long
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define repn(i,a,n) for(int i = a; i <= n; i++)
#define rep(i,a,n) for(int i = a; i < n; i++)
typedef pair<int,int> PII; 
map<char,int> mp,num;
 
void solve(){
	for(int i=1;i<=26;i++){
		mp['A'+i-1]=i;
	    num['A'+i-1]=0;
	}
	int n;
	cin>>n;
	string s;
	cin>>s;
	s=" "+s;
	int sum=0;
	for(int i=1;i<=n;i++){
		num[s[i]]++; 
	}
	for(int i=1;i<=26;i++){
		if(num['A'+i-1]>=i)
		  sum++; 
	}	
	cout<<sum<<endl;
}
 
signed main(){
	IOS;
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

B. Preparing for the Contest

  • 构造一个符合题目的序列即可,因为题目中说了如果有多个答案,则打印其中任何一个
#include
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define int long long
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define repn(i,a,n) for(int i = a; i <= n; i++)
#define rep(i,a,n) for(int i = a; i < n; i++)
typedef pair<int,int> PII; 

void solve(){
	   int n,k;
	   cin>>n>>k;
	   if(k==n-1)
	     for(int i=1;i<=n;i++)
	       cout<<i<<' ';
	    else{
	    	int m=n-k-1;
	    	while(m--)
	    	  cout<<n--<<' ';
	    	for(int i=1;i<=n;i++)
	    	  cout<<i<<' ';
		}
		cout<<endl;
}

signed main(){
	IOS;
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

C. Quests

  • 前缀和求出第一次解决问题给的经验值,在该问题之前求出最大的完成一次任务之后给的经验值b
#include
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define int long long
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define repn(i,a,n) for(int i = a; i <= n; i++)
#define rep(i,a,n) for(int i = a; i < n; i++)
typedef pair<int,int> PII; 
map<char,int> mp,num;
struct Node{
	int x,y;
}s[200010];

bool operator < (const Node &A,const Node &B){
	return A.x+A.y>B.x+B.y;
}
bool b[200010];

void solve(){
	int n,k;
	cin>>n>>k;
	vector<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,res=0;
	for(int i=1;i<=min(k,n);i++){
		sum+=a[i];
		res=max(res,b[i]);
		ans=max(ans,sum+(k-i)*res);
	}
	cout<<ans<<endl;
}

signed main(){
	IOS;
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

D. Three Activities

  • 因为需要选择三个不同的天 x,y,z,利用贪心的思想,取每个活动前三个最大的,然后求出9种情况的最大值即是朋友人数最大的,
#include
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define int long long
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define repn(i,a,n) for(int i = a; i <= n; i++)
#define rep(i,a,n) for(int i = a; i < n; i++)
typedef pair<int,int> PII; 

struct Node{
	int x,num;
}; 
bool operator < (const Node &A,const Node &B){
	if(A.x!=B.x) return A.x>B.x;
	return A.num<B.num;
} 


void solve(){
	int n;
	cin>>n;
	vector<Node> a(n+1),b(n+1),c(n+1);
	repn(i,1,n) cin>>a[i].x,a[i].num=i;
	repn(i,1,n) cin>>b[i].x,b[i].num=i;
	repn(i,1,n) cin>>c[i].x,c[i].num=i;
	sort(a.begin()+1,a.end());
	sort(b.begin()+1,b.end());
	sort(c.begin()+1,c.end());
 
	int ans=0;
	for(int i=1;i<=3;i++){
		int res=0;
		int ma=a[i].x,na=a[i].num;
	  for(int j=1;j<=3;j++){
	  	if(b[j].num==a[i].num) continue;
	  	int mb=b[j].x,nb=b[j].num;
	    for(int k=1;k<=3;k++){
	    	if(c[k].num==a[i].num||c[k].num==b[j].num)
	    	   continue;
	    	int mc=c[k].x,nc=c[k].num;
	    	res=ma+mb+mc;
	    	ans=max(ans,res);
		 }
	   }
	}
	cout<<ans<<endl;
	
}

signed main(){
	IOS;
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

E. Game with Marbles (Easy Version)

  • 也是思维题,轮到该选手出手时,有两种情况:一是该选手会选择自己身上某颜色最多的弹珠,这样打出一发弹珠后,对手丢弃所有与改弹珠颜色相同的弹珠自己身上就可以保留尽可能多的弹珠了。二是打出一发弹珠使得对面某颜色弹珠最多的都弃掉,这样得分会有利于该选手。所以该选手会选择打出一发弹珠后剩下得弹珠数量+对手弃掉得弹珠数量最大的,即权值之和最大,这里我用优先队列-(大根堆)排序。
#include
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl "\n"
#define int long long
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define repn(i,a,n) for(int i = a; i <= n; i++)
#define rep(i,a,n) for(int i = a; i < n; i++)
struct Info{
	int x,y;
};
 
bool operator < (const Info &A,const Info &B){
	return A.x+A.y<B.x+B.y;
}
 
void solve(){
	int n,ans=0;
	cin>>n;
	vector<int> a(n+1),b(n+1);
	priority_queue<Info> q;
	repn(i,1,n) cin>>a[i];
	repn(i,1,n) cin>>b[i];
	repn(i,1,n) q.push({a[i],b[i]});
	bool flag=true;//Alice出手 
	while(!q.empty()){
		auto t=q.top();
		q.pop();
		//cout<
		if(flag)
		  ans+=t.x-1,flag=false;
		else
		  ans-=t.y-1,flag=true;
	}
		
	cout<<ans<<endl;
}
/*
5
6
3 2 4 2 5 5
9 4 7 9 2 5
*/
 
signed main(){
	IOS;
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

你可能感兴趣的:(Codeforces,cocoa,macos,objective-c,算法,c++)