首页 > 其他分享 >Educational Codeforces Round 160 (Rated for Div. 2)

Educational Codeforces Round 160 (Rated for Div. 2)

时间:2023-12-20 22:11:58浏览次数:37  
标签:Educational Rated int 交换 Codeforces size

A. Rating Increase

image
image

字符串处理

#include<bits/stdc++.h>
using namespace std;
void solve(){
	string s;
	cin>>s;
	int n=s.size();
	s=" "+s;
	for(int i=1;i<=n-1;i++){
		string t="";
		for(int j=1;j<=i;j++){
			t=t+s[j];
		}
		string x="";
		for(int j=i+1;j<=n;j++)x=x+s[j];
		int a=0;
		int b=0;
		int k=1;
		for(int j=t.size()-1;j>=0;j--){
			a+=k*t[j];
			k*=10;
		}
		k=1;
		for(int j=x.size()-1;j>=0;j--){
			b+=k*x[j];
			k*=10;
		}
		if(x[0]!='0'&&a<b){
			cout<<t<<" "<<x<<"\n";
			return;
		}
	}
    cout<<-1<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

B. Swap and Delete

image
image

按贪心来说肯定能交换就交换划算,所以记录0,1个数,遇见0就拿已有的1交换,同理1,当手里的硬币不足以交换时只能删除

#include<bits/stdc++.h>
using namespace std;
void solve(){
		string s;
		cin>>s;
		int m=s.size();
		int a=0,b=0;
		for(int i=0;i<m;i++){
			if(s[i]=='0')a++;
			else b++;
		}
		int ans=0;
		for(int i=0;i<m;i++){
			if(s[i]=='0'){
				if(b)b--;
			    else{
			    	cout<<m-i<<"\n";
			    	return;
				}
			}
			if(s[i]=='1'){
				if(a)a--;
			    else{
			    	cout<<m-i<<"\n";
			    	return;
				}
			}
		}
		cout<<0<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

标签:Educational,Rated,int,交换,Codeforces,size
From: https://www.cnblogs.com/yufan1102/p/17917713.html

相关文章

  • Codeforces Round 916 (Div. 3)
    A.ProblemsolvingLogmap枚举字母#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intn; strings; cin>>n>>s; intans=0; s=""+s; map<char,int>mp; for(inti=1;i<=n;i++){ mp[s[i]]++; } for(autoc:mp)......
  • Codeforces Round 916 (Div. 3)(A~E2)
    A统计一下每个字母的出现次数然后输出即可#include<bits/stdc++.h>#definerep(i,a,b)for(registerinti=(a);i<=(b);++i)#definefep(i,a,b)for(registerinti=(a);i>=(b);--i)#definelsp<<1#definersp<<1|1#definePIIpair<int,int&......
  • [Codeforces] CF1795C Tea Tasting
    CF1795CTeaTasting题意有\(n\)个人和\(n\)杯茶,第\(i\)个人每次会喝\(b_i\)毫升的茶。第\(i\)杯茶有\(a_i\)毫升。总共会喝\(n\)轮茶,第\(j\)轮第\(i\)个人会尝试喝第\(i+1-j\)杯茶。喝的量为\(\min(a_{i+1-j},b_i)\)毫升,并且使\(a_{i+1-j}\)减少\(\mi......
  • Educational Codeforces Round 160 (Rated for Div. 2) A~C
    A.RatingIncrease题意:将一个字符串分成两个整数a和b,要求没有前导0,且a<b思路:遍历字符串s,若当前位置不是0,则拆分字符串,比较大小//#include<bits/stdc++.h>#include<iostream>#include<string>#include<cstring>#include<vector>#include<algorithm>#inclu......
  • Educational Codeforces Round 160 (Rated for Div. 2)
    基本情况A题秒了。B题卡了实在太久,BC题最后虽然都过了,但是耗时太久。感觉C对我来说更好写。B.SwapandDelete经典+3。总是一条路偏要走到黑了才会想着换思路,早该换了。一开始想了一大堆乱七八糟的思路,但都错了。后面往简单了想,这题毕竟最后必须要左对齐的,直接从左往右比......
  • 【题解】CodeForces-1913
    CodeForces-1913ARatingIncrease依题意模拟。提交记录:Submission-CodeForcesCodeForces-1913BSwapandDelete交换免费就是能任意重排,从头开始尽量填相反的,剩下只能删去了。提交记录:Submission-CodeForcesCodeForces-1913CGamewithMultiset从大到小能减则减一定......
  • 【题解】CodeForces-1905
    CodeForces-1905AConstructiveProblems发现沿着对角线放就行了,答案是\(\max(n+m)\)。提交记录:Submission-CodeForcesCodeForces-1905BBegginer'sZelda最优操作每次删两个叶子(除了最后一次只剩两个节点),所以答案是叶子个数除以二上取整。提交记录:Submission-CodeForc......
  • k8s - error: 0/1 nodes are available: 1 node(s) had untolerated taint
     WarningFailedScheduling89sdefault-scheduler0/1nodesareavailable:1node(s)haduntoleratedtaint{node.cloudprovider.kubernetes.io││/uninitialized:true}.preemption:0/1nodesareavailable:1Preemptionisnothelpf......
  • class sun.reflect.GeneratedConstructorAccessor2 cannot access its superclass sun
    在启动JFinal程序时报错classsun.reflect.GeneratedConstructorAccessor2cannotaccessitssuperclasssun.reflect.Constructor问题所在因为这个项目的原作者是使用eclipse编写的,idea和eclipse的启动机制不一样,由于eclipse并没有自动实现热加载机制,因此这里我们需要加上......
  • Codeforces Round 834 (Div. 3)
    CodeforcesRound834(Div.3)A.Yes-Yes?题意:就是Y后面跟e,e后面跟s,s后面跟Y#include<iostream>usingnamespacestd;voidsolve(){stringx;cin>>x;intl=x.size();if(l==1){if(x[0]!='Y'&&x[0]!='e&#......