Codeforces Round #534 (Div. 2) A(暴力)B(栈)C(思维)

A. Vasya and Chocolate(暴力)

题目链接:https://codeforces.com/contest/1065/problem/A

题目大意:超市举行买b个东西送c个同样的,每个东西a元,有s元,问能得到多少个东西

思路:首先int能买多少个,然后int能换多少个,相加即可

AC:

int main(){
	int n;
	while(cin>>n){
		while(n--){
			ll s,a,b,c;
			cin>>s>>a>>b>>c;
			ll res=s/c;
			ll ans=res;
			res=res/a;
			res=res*b;
			cout<<ans+res<<endl;
		}
		
	}
}

B. Game with string(栈)

题目链接:https://codeforces.com/contest/1104/problem/B

题目大意:给你一串字符串,每次能取两个相邻的相同的字符,一人一轮,问最后谁获胜,先手获胜输出Yes,后手No

思路:简单分析一下就可以直到,维护一个栈,每读入一个元素,比较一下栈顶的元素,相同都取出,然后res++,否则放入,最后判断一下res是奇数还是偶数即可。

AC:

int main(){
	stack<char> st;
	string s="";
	while(cin>>s){
		while(st.size())	st.pop();
		int l=s.size(),res=0;
		for(int i=0;i<l;++i){
			if(st.size()==0){
				st.push(s[i]);
			}
			else{
				if(st.top()==s[i]){
					st.pop();res++;
				}
				else{
					st.push(s[i]);
				}
			}
		}
		if(res%2)	cout<<"Yes"<<endl;
		else		cout<<"No"<<endl;
		s="";
	}
}

C. Grid game(思维)

题目链接:https://codeforces.com/contest/1104/problem/C

题目大意:一个4*4的盒子,每次放入2*1||1*2的木条,一行满了可以全部消掉,问每个木条放入的位置可以是什么。字符串0表示竖着放,1表示横着放。

思路:横着放的放上面一行,竖着放的放下面一行,满了就消掉。

AC:

int main(){
	string s="";
	while(cin>>s){
		int l=s.size();
		int k1=1,k2=1;
		for(int i=0;i<l;++i){
			if(s[i]=='0'){
				cout<<"3 "<<k1++<<endl;
			}
			else{
				cout<<"1 "<<k2<<endl;
				k2+=2;
			}
			if(k1==5)	k1=1;
			if(k2==5)	k2=1;
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_40482358/article/details/86656232